|Rename the Particles|
Our _Snowflake particle needs a more generic name. Let's rename it from "_Snowflake" to "_Particle". Use the Find and Replace to do this and you should get a message that nine changes were made. Test again and it still works.
Find what: _Snowflake
Replace with: _Particle
A Stage of Any Size
Our particle system is written for the default stage size of 550 x 400. Now, we will add a few variables to our program and use them to make it easier to change the stage size to match the needs of any Flash project. We will put these variables at the top of our program. It is a standard practice to put variables at the top and it makes it easy to change the values of these variables as needed. Let's call our variables "stageWidth" and "stageHeight" and give both of them a data type of Number. While we are still in the testing phase, let's keep the default width and height. Add these two lines to the top of the code.
Now we are ready to use these variables to replace the hard coded settings in our particle system. Let's first work on the line of code that places the new particles in a random position along the Y axis.
Replace the 400 with the stageHeight variable.
We can use the new variables in the line of code that tests to see if the particle has gone beyond the right edge or bottom of the stage.
Replace the 370 with the stageHeight variable and the 550 with the stageWidth variable.
Changing the code that places the particles in a random position on the X axis will be a little more complicated. Here is what we have now.
If you remember, we used the -350 to set the initial position of some particles to beyond the left edge of the stage. The 350 is about 60% of the width of the stage. Let's use math and our stageWidth variable to replace -350 with a negative value of 60% of the stageWidth.
Now let's work on the second half of the line. The 900 was used to set the initial position of some particles to beyond the right edge of the stage. The 900 is about 1.60% of the width of the stage. So we can replace 900 with the value of 1.60% of the stageWidth.
We need to make the same change to the code that recycles the particles back up to the top of the stage.
Test your movie again and it will still work.
← Back |Next →