Falling Snow
There are many different ways of creating snowfall in Flash, some more difficult than others. We’re going to use Math.random() and another function of the Math object, the Math.sin function, to create snow that falls in random places with a natural back-and-forth drift, following the path of a trigonometric sine curve.
You can create your snow before or after you create the rest of your scene, but I’ve started of by setting up a simple backdrop of snow dunes against a dark gradient sky, on a 550wx400h pixel stage.

On a new layer, draw a single fleck or flake of snow; you can use the Oval Tool to create a simple small, round blot of snow, or draw a more traditional six-pointed snowflake shape. The point is that you only need to draw one; we’re going to use ActionScripts to replicate the single snowflake and vary its characteristics.

Convert the snowflake to a Movie Clip symbol (F8).

Assign an instance name to the movie clip; this is crucial for when we have to duplicate a single snowflake to create an entire snow flurry.

First, though, let’s work on the scripts to control the individual snowflake’s random path of motion and characteristics. Select the snowflake movie clip and open the Actions panel.
We’re going to use two onClipEvent handlers on the snowflake – first an onClipEvent (load) to set the starting position, size, and opacity of the snowflake as when the movie loads, and second an onClipEvent (onEnterFrame) to control the motion. Let’s look at the onClipEvent (load) first:
onClipEvent (load) {
this._x=0 + Math.random()*575;
this._y=-50 + Math.random()*425;
this._alpha=Math.random()*100;
var size;
size=Math.random()*100;
if (size>=50 && size<=100) {
this._xscale=size;
this._yscale=size;
}
else {
this._xscale=90;
this._yscale=90;
}
}
Now let’s analyze what this enormous chunk of code does.
The lines dealing with _x and _y control the starting position of the snowflake when the movie loads; we don’t want all of the snowflakes to come from the same place, but we do want them to start above the top edge of the stage. To that end the function defines the horizontal (x) position at the 0 point (left corner) of the stage, before adding a random number between 0.0 and 0.1 that’s been multiplied by slightly more than the width of the stage so that snowflakes can fall in not just from the top, but from the side.

The vertical (y) position is similar to the horizontal, only rather than starting at 0 (the top edge of the stage) it starts at -75, so that some of the flakes will fall in from off-stage but others will already be partway down the stage when the movie first loads. It also multiplies by a value slightly greater than the height.
The _alpha parameter is set as a percentage between 0 and 100, so setting the alpha to a value of 90 would mean that the snowflake is 90% opaque. To set a random opacity for the snowflake, the section dealing with _alpha generates a random decimal and then multiplies it by 100 to assign a random alpha value.
Like the _alpha parameter, _xscale and _yscale are percentages set by the numbers 0 to 100. Rather than generate a separate random number for each, instead we assign a single random number to the variable size, and then use an if statement to determine that if the value of size is greater than or equal to 25 but less than or equal to 100. This ensures that the snowflakes generated aren’t too small to see. If the snowflakes meet those criteria, then we set the percentage of the _xscale and _yscale parameters to equal the value of size. If not, then an else statement sets the scale to 90%.
Now let’s look at the onClipEvent (enterFrame) that controls the random downward drift:
onClipEvent (enterFrame) {
pos = pos + (Math.random()*.1) ;
this._x = this._x + Math.sin(pos) ;
this._y = this._y + 1 + Math.random()*3;
if (this._y>=400) {
this._y = this._y – 500 + Math.random()*100;
this._x = 0 + Math.random()*575;
}
}
To break this down:
pos is a variable created to help control the back-and-forth drift of the snowflake; we define the x position each time that the movie enters the frame as the previous frame’s x position plus the sine of variable pos. Because a sine value can return either a positive or negative value, sometimes adding the value returned by Math.sin actually ends up subtracting from the current x position instead of adding to it, causing backwards motion. pos also changes, by generating a random number, multiplying it by .1 (this is just a random number I chose, but you can use any number you want depending how you want the snowflake to oscillate), then adding it to the value of pos from the previous iteration.
The y (vertical) position is much simpler; it’s defined as the previous y position advanced by one pixel, plus a little extra advancement that could be anywhere from .3 to 3 pixels, so that every snowflake falls at a different speed. Although my Math.random() generated number is multiplied by 3, you can again enter any integer or even a Math constant to customize your snowfall to a speed that suits you.
Lastly, an if statement checks to see if the snowflake has reached the bottom (a pixel coordinate equal to the height of the movie) and, if it has, sends it zipping back up to the top while generating a new random x position.

You’re probably ready to be done by now, but we’ve still got a little bit more to do (don’t worry, it’s not much). Once you’ve finished assigning ActionScripts to the snowflake and adjusting for the type and speed of motion that you want, return to your stage and, on a new layer created just for your actions,click on the first frame (you should only have one) and open the Actions panel.
The last thing that we’re going to do is duplicate the single snowflake to create an entire storm of random snowflake motion.
The code to duplicate the snowflake into a flurry is:
dup = Math.random()*5;
for (dup=0; dup<150; dup++) {
duplicateMovieClip(this.snowbit, “snowbit”+dup, dup) ;
}

The first thing that this script does is create a variable named dup; we’re going to use that random number in the duplicateMovieClip function that will create a copy of the snowflake and then give it a new name.
First, though, the code uses a for statement, which is a loop that continues for as long as certain parameters are met. Its format generally follows for (initial, condition, next); a function executes inside the statement until the condition that causes the loop is no longer valid. This statement is saying for the value of dup starting at 0 up until it reaches 150, add +1 to dup and execute the statement inside the brackets. (++ when added to an expression is the same as saying expression+1.)
So the variable dup now controls the maximum number of snowflakes that can exist; change 150 to any other value you’d like, depending on how much snow you want.
The duplicateMovieClip command names the movie clip to be duplicated – called by the instance name that we assigned – and then creates a new name for it by concatenating the value of dup on this iteration of the loop with a string to create a unique name each time the loop cycles. (For instance, if the first random value generated for dup is 2, then the first duplicate snowflake will be snowbit2; the second will be snowbit3, etc.)