|In this particle system tutorial series we will be creating a snow scene animation with ActionScript and FlashR. For our scene, there are many snowflakes falling at the same time. Each flake falling on the stage will be one instance of the same movie clip. So we need to write ActionScript to animate all of the instances, or snowflakes, on the stage. We will use modular, or reuseable, code that can be used to animated as many flakes as we wish.|
The best way to begin a series like this is to familiarize yourself with some of the terminology. In this first tutorial, we will take a general look at the function and function call. This function will move three flakes a certain number of pixels down the vertical axis.
To set the scene, I have created two layers in the Timeline which I have named "background" and "snowflakes". I have imported a background image into the Flash Library. With Frame 1 of the background layer selected, I dragged the background image on to the stage. Next, I imported into the Library the snowflake image as a movie clip with the name "mcSnowflake". We will animate three instances of this movie clip.
The second piece of information inside the parentheses tells Flash how we want to move the flake. Just as "snowflake" is a variable that will hold the instance name of any flake, "movement" is a variable that will hold the Number of pixels that we wish to move the flake. By using this "movement" variable, we have the option to move each individual flake a different number of pixels.
Let's skip down to the three lines of code that will "call" the function and pass the expected information to our variables.
The difference is in the information that is passed each time the function is called. The first function call tells Flash to move snowflake1_mc 10 pixels. The second call moves snowflake2_mc 20 pixels and the third call moves snowflake3_mc 30 pixels.
Now we only have to write the body of the function. This code is what will cause the flakes to move. The code for the body of a function is placed between curly brackets.
snowflake1_mc.y = 10;
The number 10 is passed from the movement variable and the instance name snowflake1_mc is passed from the snowflake variable.
When you test your movie, you will notice that the snowflakes have moved down from the top of the stage just as we wanted them to do. However, they are not moving. This is because we have only moved them once. To keep them falling down the stage, we need to change our code a little.
For reference, save your Flash movie as SnowScene1.fla. We will be using functions and function calls to run our particle system animation.