# ActionScript 3 snow

**URL:** <https://forum.kirupa.com/t/actionscript-3-snow/245309>\
**Category:** flash\
**Created:** [November 28, 2007, 1:04pm UTC](https://forum.kirupa.com/t/actionscript-3-snow/245309 "2007-11-28T13:04:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prinzessin\_mia](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@prinzessin\_mia](https://forum.kirupa.com/u/prinzessin_mia)\
**Post date:** [November 28, 2007, 1:04pm UTC](https://forum.kirupa.com/t/actionscript-3-snow/245309/1 "2007-11-28T13:04:46Z")

</div>

Help!!!  
I am a newbie and need to create some falling snow in Actionscript 3.  
I know a little bit and have had a go at it myself.  
i used the lovely tutorial Falling snow 2.0 and tried to convert the code to AS3.

Maybe someone could have a look and tell me where i am going wrong?

there’s some code attached to the 1st frame of the main timeline and then some more attached to a movie clip. i’ve created a as class and linked it to the movie clip for as3.

Here’s the original code:  
as2 on 1st frame:

[FONT=Courier New][COLOR=Blue]for (k=0; k\<70; k++) {  
import flash.display.MovieClip;  
duplicateMovieClip(this.snow, “snow”+k, k);  
}

[FONT=Verdana][COLOR=Black]as3 [/COLOR][/FONT][/COLOR][/FONT]on 1st frame[FONT=Courier New][COLOR=Blue][FONT=Verdana][COLOR=Black]:  
[FONT=Courier New][COLOR=RoyalBlue]  
this.addEventListener(Event.ENTER\_FRAME, snowFlakes);

this.addEventListener(Event.ENTER\_FRAME, allTogether);

for (k=0; k\<70; k++) {  
import flash.display.MovieClip;  
duplicateMovieClip(this.snow, “snow”+k, k);  
}

[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=Blue][FONT=Verdana][COLOR=Black]as2 [/COLOR][/FONT][/COLOR][/FONT]on movie clip[FONT=Courier New][COLOR=Blue][FONT=Verdana][COLOR=Black]:  
[FONT=Courier New][COLOR=RoyalBlue]onClipEvent (load) {  
//specifies the size of the movie stage  
movieWidth = 720;  
movieHeight = 576;

```
//variables that will modify the falling snow
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;

//giving each snowflake unique characteristics
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 75+Math.random()*100;
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;

```

}  
onClipEvent (enterFrame) {  
//putting it all together  
rad += (k/180)\*Math.PI;  
this.\_x -= Math.cos(rad);  
this.\_y += i;  
if (this.\_y\>=movieHeight) {  
this.\_y = -5;  
}  
if ((this.\_x\>=movieWidth) || (this.\_x\<=0)) {  
this.\_x = -10+Math.random()\*movieWidth;  
this.\_y = -5;  
}  
}[/COLOR][/FONT]  
[FONT=Courier New][COLOR=RoyalBlue]  
[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT]  
[FONT=Courier New][COLOR=Blue][FONT=Verdana][COLOR=Black]as3 class i created:

[FONT=Courier New][COLOR=RoyalBlue]package  
{  
import flash.display.MovieClip;  
import flash.events.MouseEvent;

```
public class Snow extends MovieClip
{
    public var i:Math;
    public var k:Math;
    
    public function snowFlakes():void
    {
        width = 720;
        height = 576;
        
        i = 1 +Math.random() * 2;
        k = -Math.PI+Math.random() * Math.PI;
        
        this.scaleX = this.scaleY=50+Math.random() * 100;
        this.alpha = 75+Math.random() * 100;
        this.x = -10+Math.random() * width;
        this.y = -10+Math.random() * height;
    }
    
    
    public function allTogether():void
    {
        //putting it all together
        Radius += (k/180)*Math.PI;
        this.x -= Math.cos(
        this.y += i;
        if (this.y&gt;=height)
        {
            this.y = -5;
        }
        if ((this.x&gt;=width) || (this.x&lt;=0))
        {
            this.x = -10+Math.random()*width;
            this.y = -5;
        }
    }
    

}

```

}

[FONT=Verdana][COLOR=Black]If somebody please could help me out? I am getting a bit desperat. Been trying all morning.

Many, many thanks!  
[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT]
