Datasheet

24
Part 1: Getting Started
Finally the display container is rotated based on mouse movement using a simple mouseX displacement
algorithm.
function myonEnterFrame(event:Event):void
{
myDisplayObject.rotationY += (CenterX - mouseX) * .01;
sortParticles();
}
The complete carousel code is listed here:
//imports classes
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Stage;
import flash.geom.Vector3D;
//Add Particle Array
var numOfParticles:uint = 12;
var particles_ary:Array = [];
var numVar:Number=0;
var myDisplayObject:Sprite= new Sprite();
var planeRadius:Number=20;
//Stage Center
var CenterX:Number = stage.stageWidth/2;
var CenterY:Number = stage.stageHeight/2;
//Place Planes on the Stage
for(var i:uint = 0; i < numOfParticles; i++)
{
//Draw a plane
var plane:Sprite = new Sprite();//instantiates plane sprite
plane.graphics.beginFill(Math.random()*0xffffff);//Assign a plane color
plane.graphics.drawRect(-60, -60, 80, 80);//draws your plane at 0,0
plane.graphics.endFill();//ends the fill
//Add plane to the stage
myDisplayObject.addChild(plane);
var angle:Number = Math.PI * 2 / numOfParticles * i;
plane.x = Math.cos(angle) * 200;
plane.z = Math.sin(angle) * 200;
plane.y =0;
Figure 1-10
c01.indd 24c01.indd 24 12/14/09 3:03:31 PM12/14/09 3:03:31 PM










