logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture


dailyclick
All times in EST

Clairvoyance: 08:00 PM

Full Schedule
g
g Flash and Animation Site

BellaOnline's Flash and Animation Editor

g

Flash CS3 Particle System - Using Variables to Write Modular ActionScript 3 Code


Control the Number of Particles

We will use our next variable to control the maximum number of particles for our particle system. We have hard coded this to 70 in the for loop statement. Let's create a new variable and name it "maxParticles" and set it to 70. Then replace the 70 in the for loop with the variable name.

var maxParticles:Number = 70;

. . .
for (var i:Number = 0; i < maxParticles; i++)

Control the Maximum Size for the Particles

When we recycle our particles back up to the top, we place then in a random position between 0 and 40 along the Y axis.

event.target.y = Math.random() * 40;

This is because the maximum size of our snowflakes are 40 pixels. However, if we use a different graphic for our particles which is a different size, we need to set the random number between 0 and the new size. We can add a variable called maxSize and replace the 40 with that variable.

var maxSize:Number = 40;

. . .
event.target.y = Math.random() * maxSize;

Control the Maximum Movement

The last variable that we will add will control the amount of pixels that our particles move downward with each cycle of the particlefall function. Now, we have this hard coded to 5 pixels for the vertical movement and 10 pixels for the horizontal movement.

else
{ event.target.y += 5; event.target.x += Math.random() * 10; }

Let's call our new variable "maxMove" and set it to 5. Then we can replace the 5 in the code with the variable and the 10 with a value of twice the variable.

var maxMove:Number = 5;

. . .
else
{ event.target.y += maxMove; event.target.x += Math.random() * (maxMove * 2); }

Test your movie. With all these changes, it still works. But we might also wish to use a different source for our particle other than the mcSnowflake movie clip.

Change the Particle Source

If you remember, we are using the mcSnowflake movie clip as the source for our particles. Each time the program cycles through the for loop, it creates an instance of the mcSnowflake and adds it to the display list.

var _Particle:mcSnowflake;


_Particle = new mcSnowflake();


Let's assume that we want to make it rain and we have created a movie clip that we named mcRain. To use this movie clip, we just replace the "mcSnowflake" with "mcRain" in two lines of code in our program.

var _Particle:mcRain;


_Particle = new mcRain();

Test your movie. Save your movie as particle_system.fla.

Now, let's see if it still works correctly when we change the value of the variables. Go to the Properties panel and change the size of the stage to 800 x 600. Next, go back to the Actions panel and change the value of the stageWidth to 800 and the stageHeigth to 600. Change the size of the particles to 30, number of particles to 50 and maximum movement in pixels to 20. Test your movie again and it should still work.

And we have finally come to the end of this series. You have a modular particle system code that you can use as a starting point to build any Flash project that needs a particle system. Just import a graphic or draw an object, convert it to a movie clip symbol and give it a unique name. Then, in the Actions panel, plug in the values for the variables and rename the mcSnowflake movie clip. You can now tell everyone that you have created your own particle system in Flash CS3. Here is the finished code.

← Back





Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Twitter Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Facebook Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to MySpace Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Del.icio.us Digg Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Yahoo My Web Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Google Bookmarks Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Stumbleupon Add Flash+CS3+Particle+System+%2D+Using+Variables+to+Write+Modular+ActionScript+3+Code to Reddit



 



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


For FREE email updates, subscribe to the Flash and Animation Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 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.

g


g features
Motion 5 Parallax Effect - The Graphics

Animate Lower Third in Motion 5

Drop Zone and Lower Third in Motion 5

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor