Friday, December 28, 2012

ActionScript 3.0 demo: create a falling snow in flash CS6



Below is the example to create falling snow in Flash CS6 using ActionScript 3.0.
1) Open Adobe Flash CS6 File->New->ActionScript 3.0
2) Stage width 640, height 400, File-> import to stage with background image (640*400) in layer 1.
Create static text, "SUM" and author name.  input web address under the author name link property.
3) Create layer 2. Using  oval tool to create   a circle with stroke color and fill color white..
4) Using  select tool, to convert the white circle to MovieClip with name snowflake and select "export to actionscript" with class name snowflake.
5) Press F9 to input the following actionscritpt

addEventListener (Event.ENTER_FRAME,snow);
function snow (event:Event):void {
   
    var scale:Number=Math.random()*.6;
    var _sf:snowflake=new snowflake();
    _sf.x=Math.random()*640;
    _sf.scaleX=scale;
    _sf.scaleY=scale;
    var speed:Number=Math.random()*2;
    var RA:Array=new Array(-1,1);
    var lf:int=RA[Math.round(Math.random())];

    stage.addChild (_sf);
    _sf.addEventListener (Event.ENTER_FRAME,snowfall);
   

    function snowfall (event:Event):void {
       
        _sf.y+=speed;
        _sf.rotation+=Math.random()*20;
        _sf.x+=(Math.random()*2)*lf;
    }
}

6) Export or test flash, done.

flash output

video: ActionScript 3.0 demo: create a falling snow in flash CS6

5 comments:

  1. Thanks, this code works really well for a project I'm working on. However I can't seem to get an object in front of the snow. Any advice on how to get the snow to go behind one of the layers?

    ReplyDelete
    Replies
    1. Hi Brady, did you figure this out? I am having the same problem.

      Delete
    2. A bit late..... but try to nest this code in a movie clip that you put on a layer behind the object you want in front on the main timeline....

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. this works well.can i know how to stop this in one scene?? because this appears in all scenes in my project. i just need to stop the snow falling in one scene

    ReplyDelete