Solved

converting script to as3

Posted on 2008-10-27
4
241 Views
Last Modified: 2013-11-11
Hi,

I am trying to convert Kirupa's snow script (http://www.kirupa.com/developer/flash8/snow.htm) from AS2 to AS3.

I am getting no errors but also no snow. The fla is attached (with .jpg extension), I am sure it is a basic mistake, I just cannot find it.
snowAS3.fla.jpg
0
Comment
Question by:Hulfy
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 22812605
ok a couple of things that need to change. (i used the version directly from kirupa not  yours)

1. i changed the variables width and height to w and h respectively - lets not use reserved words as variable names.
2. i just changed the function syntax to what I like
instead of init = function i use function init();
3. attachMovie doesn't exist anymore you need to add the object to your displayList
so
t = new snow(); instead of attachMovie.
4. you need to change all the variables with underscores to no more underscores i.e. _x is now x; _alpha is now alpha.
5. you need to use an event listener for enterframe now, its no longer working in AS3.
t.addEventListener(Event.ENTER_FRAME, mover);
6, in the mover function target the snow object NOT THE main timeline.
and that's it - we got snow.

have a go and if you're stuck i'll upload the file.
0
 

Author Comment

by:Hulfy
ID: 22819930
Thanks for your help.


I thought I did everything you said. I am getting no errors but no snow.  Can you upload the fla ?


Thanks.

 
     function init () {
 
    w= 300;
    // pixels
    h = 200;
    // pixels
    max_snowsize = 10;
    // pixels
    snowflakes = 50;
    // quantity
    for (i=0; i<snowflakes; i++) {
	
    t = new snow();
    t.alpha = 20+Math.random()*60;
    t.x = -(w/2)+Math.random()*(1.5*width);
    t.y = -(h/2)+Math.random()*(1.5*height);
    t.scaleX = t.scaleY=50+Math.random()*(max_snowsize*10);
    t.k = 1+Math.random()*2;
    t.wind = -1.5+Math.random()*(1.4*3);
    t.addEventListener(Event.ENTER_FRAME, mover);
 
    }
 
    };
    mover = function() {
  
  
    t.y += t.k;
    t.x += t.wind;
    if (t.y>h+10) {
 
    t.y = -20;
 
    }
    if (t.x>w+20) {
 
    t.x = -(w/2)+Math.random()*(1.5*w);
    t.y = -20;
 
    } else if (t.x<-20) {
 
    t.x = -(w/2)+Math.random()*(1.5*w);
    t.y = -20;
 
    }
 
    }
    init();

Open in new window

0
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 22829318
sorry i took so long adsl line was down.
here you go.
just remove the .txt extension.
the thing is you're referencing t in the mover function, but t doesn't have scope there as its created inside another function.
so you use the event listener target.
snow3-AS3.fla.txt
0
 

Author Comment

by:Hulfy
ID: 22849449
thanks blue-genie
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Does Flash have a Firefox problem? 5 326
flash cs6 4 350
How to stream IP Cam to Flash Media Server with or without Flash Media Live Encoder 5 1,391
PDF edit software 2 38
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question