forked from: forked from: flash on 2010-4-28

by umhr forked from forked from: flash on 2010-4-28 (diff: 23)
♥0 | Line 79 | Modified 2010-04-28 18:54:33 | MIT License
play

ActionScript3 source code

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

// forked from aktm's forked from: flash on 2010-4-28
// forked from aktm's flash on 2010-4-28
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    
    public class Main extends Sprite {
    	
		private var _sikakus:Array;
		private var _maru:Sprite;
		private var _btn:Sprite
    	    
        public function Main() {
			_sikakus = [];
			
        	    //放射状の線を描画
            this.graphics.lineStyle(2,0x00ffff);
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(200,50); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(150,100);
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(100,150); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(50,200);
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(100,250); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(150,300); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(200,350);
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(250,300);
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(300,250); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(350,200); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(300,150); 
            this.graphics.moveTo(200,200);
            this.graphics.lineTo(250,100);
            
            //ボタン、クリックできる範囲がとても狭いのはなぜ?
			//→tfが同じ位置にあって、そちらへのマウスの反応が優先されるから。
            _btn = new Sprite();
            _btn.graphics.beginFill(0x00ffff);
            _btn.graphics.drawCircle(200,200,20);
            _btn.graphics.endFill();
            _btn.buttonMode = true;
            _btn.addEventListener(MouseEvent.CLICK,onClick);            
            this.addChild(_btn);                       
            
            this.addEventListener(Event.EXIT_FRAME,onEnter);
                       
            var tf:TextField = new TextField();
            tf.text = "CLICK";
            tf.textColor = 0x000000;
            tf.selectable = false;
			//マウスに反応しないようにする。
			tf.mouseEnabled = false;
            tf.x = 180;
            tf.y = 190;
            addChild(tf);
            
            //回る丸
            _maru = new Sprite();
            _maru.graphics.beginFill(0x800000,0.75);
            _maru.graphics.drawCircle(150,10,10);
            _maru.graphics.endFill();
            _maru.x = 200;
            _maru.y = 200;
            this.addChild(_maru);
            
        }
        //クリックで四角を描画。クリックするごとに少しずつ回転したものを重ねて描画したいのに動きません。
        private function onClick(e:MouseEvent):void{
        	   var _sikaku:Sprite = new Sprite;
        	   _sikaku.graphics.beginFill(0x0000ff,0.2);
        	   _sikaku.graphics.drawRect(-50,-50,100,100);
        	   _sikaku.x = stage.stageWidth*Math.random();
        	   _sikaku.y = stage.stageHeight*Math.random();
			   _sikaku.rotation = Math.random() * 90;
        	   this.addChild(_sikaku);
			   _sikakus.push(_sikaku);
        }
        
        private function onEnter(event:Event):void{
        	_maru.rotation ++;
			var n:int = _sikakus.length;
			for (var i:int = 0; i < n; i++) {
				_sikakus[i].rotation ++;
				
			}
			
        }
    }
}