# Flying Out Particle System Flash ActionScript Tutorial

Step 4: Finalize the Particle System

The Flash Particle System is almost finished. However we don't like the big star particles on the stage when the Flash Movie just started.

Please update flash player to view this Flash ActionScript tutorial!

## Flash Tutorial Content:

The Flash ActionScript Fly Out Particle System is not perfect. You should noticed that there are some big star particles appear when the Flash Movie starts. The big star particles are newly created and still moving out of the stage. We can remove them by making them invisible when newly created on the stage.

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
addChild(star);

// 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;

// We don't want to see the Stars when newly added to the stage
star.visible = false;

// 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
stage.addEventListener(Event.ENTER_FRAME, flyingOut);

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;

// Scale up the size of stars
starParticles.scaleX += 0.01;
starParticles.scaleY += 0.01;

// Do some rotation effect while the Stars flying out
starParticles.rotation += 2;

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

// Scale down all the stars
starParticles.scaleX = 0.0001;
starParticles.scaleY = 0.0001;

// 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;

// Set the Stars visible again
starParticles.visible = true;

}
}

}

## Download Flash Source File: Just click here to download the source code for this tutorial.

Remarks:

This Flash ActionScript Particle System tutorial shows how to create a Fly Out effect flash particle system.