package { import flash.display.MovieClip; import flash.display.Shape; import flash.events.Event; import flash.events.TimerEvent; import flash.utils.Timer; import caurina.transitions.Tweener; import com.theflashblog.fp10.SimpleZSorter; public class CircleSaver extends MovieClip { static var count:int = 50; // the count of Ovals private var mc:MovieClip; // container of Ovals private var counted:int = 0; // number of Ovals Created private var Shapes:Array = new Array(); // an Array For Storing Ovals Data private var timer:Timer = new Timer(5000, int.MAX_VALUE); //time for next Tween public function CircleSaver() { setApplication(); } // set the Application Properties private function setApplication():void { Shapes = new Array(); mc = new MovieClip(); mc.x = 0; mc.y = 0; mc.z = 0; addChild(mc); timer.addEventListener(TimerEvent.TIMER, doTween); stage.addEventListener(Event.ENTER_FRAME, nextCircle); } //=============================== Tweening Functions ============================== //================================================================================= // Tweerner Function private function doTween(e:TimerEvent):void { var item:int = Math.random()* Shapes.length - 1; var sh:Shape = Shapes[item]; sh.alpha = 1; // using the Tweener Class Tweener.addTween(mc, {x:sh.x, y:sh.y, z:sh.z, rotationX:mc.rotationX + 10, rotationY:mc.rotationY + 10, rotationZ:mc.rotationZ + 10, time:4, transition:"easeInOutQuart"}); } //================================ Creatintg Ovals ================================ //================================================================================= private function createCircle():void { var sh:Shape = new Shape(); // position of shape var x_:int = (Math.random()* 1000) - 500; var y_:int = (Math.random()* 1000) - 500; var z_:int = (Math.random()* 50) - 20; // shape Propeties var borderSize:uint = 1; var alpha_:Number = Number((Math.random() * .5) + .3); var size:uint = uint(Math.random()*100) + 200; var bgColor:uint = uint(Math.random()* 0xFFFFFF); var borderColor:uint = uint(Math.random()* 0xFFFFFF);; // set distance of Object sh.z = z_ * 200; sh.alpha = .4; // create Oval sh.graphics.beginFill(bgColor, alpha_); sh.graphics.lineStyle(borderSize, borderColor) sh.graphics.drawCircle(x_, y_, size); sh.graphics.endFill(); // adding shape to display list mc.addChild(sh); // adding shape to an Array Shapes.push(sh); } // shooting the createCircle() function til all Ovals to be created private function nextCircle(e:Event):void { if (counted <= count){ counted++; createCircle(); } else { SimpleZSorter.sortClips(mc); //for Sorting Ovals On Z-Space stage.removeEventListener(Event.ENTER_FRAME, nextCircle); doTween(null); //make first Move timer.start(); //start Tweener Timer } } } }