removeEventListenerの練習

by Nowloading_ forked from F5B2D仕様の020504だったか (diff: 73)
なんとなく完成した。
ソースは奇麗じゃない(特にボタン)

赤ボタンで枠内にランダムに円の生成
青ボタンで枠内のクリア(枠内を黒く)
緑ボタンで円の生成を中止
♥0 | Line 83 | Modified 2010-10-27 01:19:38 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import frocessing.core.F5BitmapData2D;
    [SWF(wisth=465,height=465,backgroundColor=0x222222,flameRate = 30)]
    public class F5B2D extends Sprite {    
        private var fb:F5BitmapData2D;   
        private var b1:Sprite;
        private var b2:Sprite;
        private var b3:Sprite;
        private var mat:Matrix;
        
        //メインファンクション    
        public function F5B2D() {
            graphics.lineStyle(1,0xffffff);
            graphics.drawRect(48,29,366,262);
            DrawMode();
            button();
            Add();          
        }
        //F5BitmapData2Dの描画設定
        public function DrawMode():void{
            fb = new F5BitmapData2D( 364, 260, false, 0 );
            mat = new Matrix();
            fb.blendMode = "add";       
            fb.colorMode( "rgb", 364,1,260,255);
            var bit:Bitmap = new Bitmap(fb.bitmapData);
            bit.x=49;
            bit.y=30;
            addChild(bit);         
        }
        //ボタンの生成
        public function button():void{
            b1 = new Sprite();
            b1.graphics.lineStyle(3,0xff0000);
            b1.graphics.beginFill(0xcc0000);
            b1.graphics.drawRoundRect(400,390,60,40,5,5);
            b1.graphics.endFill();
            b1.buttonMode = true;
            addChild(b1);
                        
            b2 = new Sprite(); 
            b2.graphics.lineStyle(3,0x0000ff);
            b2.graphics.beginFill(0x0000cc);
            b2.graphics.drawRoundRect(330,390,60,40,5,5);
            b2.graphics.endFill();
            b2.buttonMode = true;
            addChild(b2);
            
            b3 = new Sprite(); 
            b3.graphics.lineStyle(3,0x00ff00);
            b3.graphics.beginFill(0x00cc00);
            b3.graphics.drawRoundRect(260,390,60,40,5,5);
            b3.graphics.endFill();
            b3.buttonMode = true;
            addChild(b3);            
        }
        //イベントリスナー登録
        public function Add():void{
            b1.addEventListener(MouseEvent.MOUSE_DOWN,start);
            b2.addEventListener(MouseEvent.MOUSE_DOWN,clear);
            b3.addEventListener(MouseEvent.MOUSE_DOWN,stop);
        }
        //enter_frame
        public function start(e:Event):void{
                addEventListener(Event.ENTER_FRAME,Draw);       
        }
        //ランダムな円の生成
        public function Draw(e:Event):void{
                fb.beginDraw();             
                var cx:int = Math.random()*364;
                var cy:int = Math.random()*260;            
                fb.fill(cx,1,cy,Math.random()*45);
                fb.noStroke();        
                fb.circle(cx,cy,Math.random()*40);
                fb.endDraw();                            
        }
        //描画領域のクリア
        public function clear(e:MouseEvent):void{
            fb.blendMode="normal";
            fb.fill(0);
            fb.beginDraw();
            fb.rect(0,0,364,260);
            fb.endDraw();
        }
        //ランダム円の生成のストップ
        public function stop(e:MouseEvent):void{
            removeEventListener(Event.ENTER_FRAME,Draw);
        }  
    }
}

Forked