Animation

  1. Home
  2. Computing & Technology
  3. Animation

Flash Falling Snow with Random Functions and Movie Clips

By Adrien-Luc Sanders, About.com

10 of 10

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.)

That just about covers it – and with that done, all that’s left to say is...let it snow.

Explore Animation

About.com Special Features

Animation

  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.