forked from: simple square Shapes animation
/**
* Copyright ninjitsu ( http://wonderfl.net/user/ninjitsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yhcq
*/
// forked from www0z0k's simple square Shapes animation
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
public class FlashTest extends Sprite {
private var oldSchoolMC:MovieClip;
private var xx:Number = root.mouseX;
private var yy:Number = root.mouseY;
private var sub:Number = 20;
private var coe:Number = 0;
public function FlashTest() {
// write as3 code here..
oldSchoolMC = new MovieClip();
addChild(oldSchoolMC);
oldSchoolMC.x = 150;
oldSchoolMC.y = 150;
oldSchoolMC.buttonMode = true;
addFrames();
oldSchoolMC.addEventListener(Event.ENTER_FRAME, onEnterFrame);
oldSchoolMC.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void{
if(oldSchoolMC.hasEventListener(Event.ENTER_FRAME)){
oldSchoolMC.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}else{
oldSchoolMC.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
private function addFrames():void {
for (var i:int = 0 ; i < 0xffffff ; i+=1000000) {
oldSchoolMC.addChild(genColRect(i));
if (oldSchoolMC.numChildren > 0) {
oldSchoolMC.getChildAt(oldSchoolMC.numChildren - 1).scaleX -= (sub - oldSchoolMC.numChildren);
oldSchoolMC.getChildAt(oldSchoolMC.numChildren - 1).scaleY -= (sub - oldSchoolMC.numChildren);
}
}
}
private function onEnterFrame(e:Event):void {
for (var i:int = 0 ; i < oldSchoolMC.numChildren ; i++) {
oldSchoolMC.getChildAt(i).rotation += (oldSchoolMC.numChildren - i)/sub;
}
}
private function genColRect(col:int = 0x00cccc):Shape {
var spr:Shape = new Shape();
spr.graphics.beginFill(col);
spr.graphics.drawRect( -50, -50, 100, 100);
spr.graphics.endFill();
return spr;
}
}
}