マウスボタンを押している間、円を書く

by ongaeshi forked from クリックした場所に円を描く (diff: 23)
♥0 | Line 29 | Modified 2009-12-28 15:03:35 | MIT License
play

ActionScript3 source code

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

// forked from 9re's クリックした場所に円を描く
package {
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;

    public class MouseClick extends Sprite {
	private var isDown:Boolean;
	
        public function MouseClick() {
	    // ボタン押している
	    isDown = false;
	    
            // ステージにクリック・イベントのハンドラを登録する
            stage.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void {isDown = true;}); 
            stage.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void {isDown = false;}); 
            stage.addEventListener(Event.ENTER_FRAME, enterFrame); 
        }

	private function enterFrame(e:Event):void {
	    if (isDown) {
		// 半径をランダムでセット
		var nR:int = Math.ceil(Math.random() * 20) + 10; 
		// 色をランダムで選ぶ
		var color:int = Math.floor(Math.random() * 0xffffff);
		
		// 円の生成
		addChild(new DrawCircle1(stage.mouseX, stage.mouseY, nR, color));
	    }
	}
    }
} 

import flash.display.MovieClip; 

class DrawCircle1 extends MovieClip {
    public function DrawCircle1(nX:int, nY:int, nR:int, color:int) { 
        // 線の太さを2, 色をcolorにセットする
        graphics.lineStyle(2, color);
        // nX, nYを中心とする半径nRの円を描く
        graphics.drawCircle(nX, nY, nR); 
    } 
}