Using Variables for Modular Particle System

Using Variables for Modular Particle System
When we began this FlashR CS3 particle system series of tutorials, we created a simple, modular function and demonstrated that we could use that function to animate three instances of the same movie clip. Since that first tutorial, we have come a long way and have built a particle system in ActionScriptTM 3. But how modular is this latest particle system? Can it be used for movie clips other than our mcSnowflake? Can we use it for a Flash movie that has a smaller or larger stage? Can we use a movie clip of a different size? Can we easily increase or decrease the maximum number of movie clips or the speed at which they fall down the stage?

Because this was a beginner's tutorial with many things to learn, the particle system was written using specific, hard coded settings for these features. But now that you have completed your particle system, we can make a few changes to the program code that will make it more modular and reuseable.

Rename the Functions

When we were only concerned with learning how to animate our snowflake movie clip, it was easier to name the function that created our snowflakes "snowflake" and the function that animated the snowflakes "snowfall". To make our program more versatile, we need to rename the functions with more generic names that still reflect the purpose of the functions.

Because this is a particle system, another name for the function that creates the snowflake can be "createParticles". Let's rename the snowflake function from "snowflake()" to "createParticles()".

At the top of the Actions panel, you will see a Find and Replace icon. Click on this icon to open the Find and Replace dialog box. In this dialog box, check the option called "Match Case" and use the following values.

Find what: snowflake()
Replace with: createParticles()

You should get a message that two were found and replaced. Repeat this step to rename the second function from "snowfall()" to "particlefall()". Again you will see two have been changed. Close the dialog box and test your movie. It still works.

Next →

Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.

Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map

Content copyright © 2022 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.