illusion_02

by greentec
♥0 | Line 67 | Modified 2014-05-30 10:03:59 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    public class FlashTest extends Sprite {
        
        public var blue:Sprite;
        public var yellow:Sprite;
        public var greenDot:Sprite;
        public var redDot:Sprite;
        public var frame:uint=0;
        
        public function FlashTest() {
            // write as3 code here..
            
            this.graphics.beginFill(0x000000);
            this.graphics.drawRect(0,0,465,465);
            
            blue=new Sprite();
            blue.x = 465/2;
            blue.y = 465/2;
            var blueG:Graphics = blue.graphics;
            blueG.lineStyle(4,0x0000ff);
            var i:int;
            var j:int;
            for(i=0;i<7;i+=1)
            {
                for(j=0;j<7;j+=1)
                {
                    blueG.moveTo(-465/2+(465-20)/6*i+10,-465/2+(465-20)/6*j-10);
                    blueG.lineTo(-465/2+(465-20)/6*i+10,-465/2+(465-20)/6*j+30);
                    
                    blueG.moveTo(-465/2+(465-20)/6*i-10,-465/2+(465-20)/6*j+10);
                    blueG.lineTo(-465/2+(465-20)/6*i+30,-465/2+(465-20)/6*j+10);
                }

            }

            addChild(blue);
            
            yellow=new Sprite();
            yellow.graphics.beginFill(0xffff00);
            yellow.graphics.drawCircle(465/2,465/3,4);
            yellow.graphics.drawCircle(465/3,465/3*2,4);
            yellow.graphics.drawCircle(465/3*2,465/3*2,4);
            addChild(yellow);
            
            greenDot=new Sprite();
            greenDot.graphics.beginFill(0x00ff00);
            greenDot.graphics.drawCircle(465/2,465/2,5);
            addChild(greenDot);
            
            
            redDot=new Sprite();
            redDot.graphics.beginFill(0xff0000);
            redDot.graphics.drawCircle(465/2,465/2,5);
            
            addEventListener(Event.ENTER_FRAME, onLoop);
        }
        
        public function onLoop(e:Event):void
        {
            blue.rotation += 1;
            frame+=1;
            if (frame>30)
            {
                frame-=30;
                if(contains(greenDot))
                {
                    removeChild(greenDot);
                    addChild(redDot);
                }
                else
                {
                    removeChild(redDot);
                    addChild(greenDot);
                }


            }

        }

    }
}