Event flow

by yooyke
stopPropagation
stopImmediatePropagation

この違いを確かめてみるテスト
♥0 | Line 52 | Modified 2011-02-05 23:47:07 | MIT License
play

ActionScript3 source code

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

package {
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.display.AVM1Movie;
    import flash.events.Event;
    import flash.display.Sprite;
    import net.hires.debug.Stats;
    
    public class FlashTest extends Sprite {
        private var tf_:TextField;
        
        public function FlashTest() {
            // write as3 code here..
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event=null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            tf_ = new TextField();
            tf_.multiline = true;
            tf_.mouseEnabled = false;
            tf_.mouseWheelEnabled = false;
            tf_.selectable = false;
            tf_.width = stage.stageWidth;
            tf_.height = stage.stageHeight;
            addChild(tf_);
            
            var sp:Sprite = new Sprite();
            sp.graphics.beginFill(0, 1);
            sp.graphics.drawRoundRect(0, 0, 128, 48, 16);
            sp.graphics.endFill();
            sp.x = stage.stageWidth / 2 - sp.width / 2;
            sp.y = stage.stageHeight / 2 - sp.height / 2;
            sp.buttonMode = true;
            sp.useHandCursor = true;
            sp.addEventListener(MouseEvent.CLICK, onClick0, false);
            sp.addEventListener(MouseEvent.CLICK, onClick1, false);
            addChild(sp);
            
            addEventListener(MouseEvent.CLICK, onParentClick);
            stage.addEventListener(MouseEvent.CLICK, onStageClick);
            
            //addChild(new Stats());
        }
        
        private function onClick0(e:MouseEvent):void {
            tf_.appendText("child 0 click\n");
            
            e.stopPropagation();
            //e.stopImmediatePropagation();
        }
        
        private function onClick1(e:MouseEvent):void {
            tf_.appendText("child 1 click\n");
        }
        
        private function onParentClick(e:MouseEvent):void {
            tf_.appendText("parent click\n");
        }
        
        private function onStageClick(e:MouseEvent):void {
            tf_.appendText("stage click\n");
        }
    }
}