flash on 2009-12-14

by silvercat
♥0 | Line 63 | Modified 2009-12-16 02:01:30 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.*;
    import flash.utils.*;
    import flash.events.*;
    import mx.controls.*;

    public class Main extends Sprite {
    		
    	
        private var myTimer:Timer = new Timer(1, 0);
        public var line2:Shape = null;
        private var wid:int = 10;
        private var cnt1:int = 5;
        private var cnt2:int = 10;
        private var cnt1_:int = 0;
        private var cnt2_:int = 0;
        
        public function Main() {
            var line:Shape = new Shape();
            line.graphics.lineStyle(0, 0x00ff00);
            line.graphics.beginFill(0x00ff00);
            line.graphics.moveTo(20,20);
            line.graphics.lineTo(100,20);
            line.graphics.endFill();
            
            this.addChild(line);
            
            var rect:Shape = new Shape();
            rect.graphics.lineStyle(0, 0xff0000);
            rect.graphics.beginFill(0xff0000);
            rect.graphics.drawRect(0, 0, 100, 10);
            rect.graphics.endFill();
            rect.x = 50;
            rect.y = 50;

            this.addChild(rect);

            line2 = new Shape();
            line2.graphics.lineStyle(0, 0x00ff00);
            line2.graphics.beginFill(0x00ff00);
            line2.graphics.drawRect(0, 0, 10, 10);
            line2.graphics.endFill();
            line2.x = 50;
            line2.y = 100;

            this.addChild(line2); 
                       
            myTimer.addEventListener(TimerEvent.TIMER, onTick );
            myTimer.start();
        }
        
        public function onTick(evt:TimerEvent):void {
        	
        		if (wid > 100) {
        			wid = 0;
        		}
        		
        		if (cnt1_ < cnt1)  {
        			cnt1_ += 1;
        			return;
        		}
        		else if ( cnt1_ == cnt1) {
        			cnt1_ = 0;
        		}
        		
			wid += 1;
        		line2.graphics.clear();
        		
        		line2.graphics.lineStyle(0, 0x0000ff);
            line2.graphics.beginFill(0x0000ff);
            line2.graphics.drawRect(0, 0, wid, 10);
            line2.graphics.endFill();
            line2.x = 50;
            line2.y = 150;
            
            this.addChild(line2);
        }
    }
}