1. Home
  2. Computing & Technology
  3. Animation

Flash Falling Snow with Random Functions and Movie Clips

By Adrien-Luc Sanders, About.com

6 of 10

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.

Explore Animation
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Flash Falling Snow with Random Functions and Movie Clips

©2009 About.com, a part of The New York Times Company.

All rights reserved.