forked from: simple square Shapes animation

by www0z0k forked from simple square Shapes animation (diff: 2)
♥0 | Line 49 | Modified 2011-11-07 05:27:25 | MIT License
play

ActionScript3 source code

/**
 * Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/q3z5
 */

// 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;
    [SWF(frameRate="2")]
    public class FlashTest extends Sprite {
        private var oldSchoolMC:MovieClip;
        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+=100000) {
                oldSchoolMC.addChild(genColRect(i));
                if (oldSchoolMC.numChildren > 0) {
                    oldSchoolMC.getChildAt(oldSchoolMC.numChildren - 1).scaleX = (250 - oldSchoolMC.numChildren) / 250;
                    oldSchoolMC.getChildAt(oldSchoolMC.numChildren - 1).scaleY = (250 - oldSchoolMC.numChildren) / 250;
                }
            }
            
        }
        private function onEnterFrame(e:Event):void {
            for (var i:int = 0 ; i < oldSchoolMC.numChildren ; i++) {
                oldSchoolMC.getChildAt(i).rotation += (oldSchoolMC.numChildren - i);
            }        
        }
        
        private function genColRect(col:int = 0xffffff):Shape {
            var spr:Shape = new Shape();
            spr.graphics.beginFill(col);
            spr.graphics.drawRect( -50, -50, 100, 100);
            spr.graphics.endFill();
            return spr;
        }        
    }
}