Datasheet

18
Part 1: Getting Started
particles_ary[i].alpha method to change the alpha of each particle based on their ith position.
Center the particle system on the stage by adding CenterX, and CenterY to the particle x, y
positions.
for(var i:uint = 0; i < particles_ary.length; i++)
{
//ball parametric orbit x
var newAngle:Number=myAngle+i/20;
particles_ary[i].alpha=1/(i+1)+.2;
particles_ary[i].x = (100+60*Math.cos(2*newAngle))*Math.cos(newAngle/
4)+CenterX;
//ball parametric orbit y
particles_ary[i].y = (100+60*Math.cos(2*newAngle))*Math.sin(newAngle/
4)+CenterY;
//ball parametric orbit z
particles_ary[i].z = 60*Math.sin(2*newAngle);
}
The results are shown in Figure 1.8 and result in a wormlike entity orbiting a torus. The key to creating
particle systems and controlling them is to stuff the individual particles into an array upon creation. And
then iterate over each particle during the frame loop of the animation sequence.
Figure 1-8
Putting it all together, the entire code is show below:
//imports sprite and stage class
import flash.display.Sprite;
import flash.display.Stage;
//Add Particle Array
var numOfParticles:uint = 100;
var particles_ary:Array = [];
var numVar:Number=0;
var ballRadius:Number=10;
//Stage Center
var CenterX:Number = stage.stageWidth/2;
var CenterY:Number = stage.stageHeight/2;
c01.indd 18c01.indd 18 12/14/09 3:03:29 PM12/14/09 3:03:29 PM