# Flying Out Particle System Flash ActionScript Tutorial

Step 2: Animate Particles

Now all particles (stars) were created in our Flash Particle System. Let's animate them in this step.

Please update flash player to view this Flash ActionScript tutorial!

## Flash Tutorial Content:

The Flash ActionScript Particle System is now jammed with star particles. Don't bother with the particle size at this moment. Let's try to animate the particles in this step.

The Flash Movie of this Flash ActionScript Particle System tutorial is shown as above.

## Flash ActionScript Codes:

// Declare number of Star
var numOfStar:uint = 30;

// Create an Array to hold the Stars
var starArray:Array = new Array();

// Creates 30 Stars on the stage.
for (var i:uint = 0; i < numOfStar; i++) {

// Create a new Star
// Remember to set linkage in Movie Library
var star:Star = new Star();

// Add the Star to the stage

// Assign start location of Star
// stage.stageWidth = 512
// stage.stageHeight = 384
// Math.random returns value between 0 - 1
star.x = Math.random() * 512;
star.y = Math.random() * 384;

// Assign random alpha to Stars if you like
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0.4 + 0 = 0.4
// Maximum value = 0.4 + 0.6 = 1.0
// Summary:
// Assign random alpha between 0.4 and 1.0
//star.alpha = 0.4 + Math.random() * 0.6;

// Assign random velocity (y-axis) to the Ball
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0 - 5 = -5
// Maximum value = 10 - 5 = +5
// Summary:
// Math.random returns value between -5 to 5
star.yVelocity = Math.random() * 10 - 5;
star.xVelocity = Math.random() * 10 - 5;

// We don't want Stars moving too slowly on the satge
// Adjust the speed in this case
if ( (star.yVelocity > -0.5) && (star.yVelocity < 0.5) ) {

star.yVelocity = 1.0;
}
if ( (star.xVelocity > -0.5) && (star.xVelocity < 0.5) ) {
star.xVelocity = 1.2;
}

// Put Star into starArray Array to be used later for animation
starArray.push(star);

}

// Add ENTER_FRAME Event to animate the Rain Drops

function flyingOut(evt:Event):void {

// Animate the Stars one by one that hold in the Array
for (var i = 0; i < starArray.length; i++) {
var starParticles = starArray[i];

// Stars moving out (flying out) from the center
starParticles.y += starParticles.yVelocity;
starParticles.x += starParticles.xVelocity;

// If the Stars move out the stage
if ( (starParticles.x > 512) || (starParticles.x < 0) || (starParticles.y > 384) || (starParticles.y < 0) ) {

// Locate the Stars back to the center of satge
// NOTE:
// stage.stageWidth and stage.stageHeight not working in rubbish IE 6.0
starParticles.x = 256;
starParticles.y = 192;

}

}
}

Remarks:

This Flash ActionScript Fly Out Particle System tutorial shows how to animate particles.