as3 阻止后续侦听器

public class Test1 extends Sprite
    {
        private var spr:Sprite;
        private var spr2:Sprite;
        public function Test1()
        {
            spr = new Sprite();
            spr.graphics.beginFill(0xff0000,1);
            spr.graphics.drawCircle(100,100,10);
            spr.graphics.endFill();
            this.addChild(spr);
            spr.addEventListener(MouseEvent.CLICK,_hander);
            spr.addEventListener(MouseEvent.CLICK,_hander);
            spr.addEventListener(MouseEvent.CLICK,_hander);
            spr.addEventListener(MouseEvent.CLICK,_hander);
            
            spr2 = new Sprite();
            spr2.graphics.beginFill(0xff0000,1);
            spr2.graphics.drawCircle(200,100,10);
            spr2.graphics.endFill();
            this.addChild(spr2);
            spr2.addEventListener(MouseEvent.CLICK,_hander2);
        }
        private function _hander(evt:MouseEvent):void
        {
            trace("click");
        }
        private function _hander2(evt:MouseEvent):void
        {
            trace("click2");
            spr.removeEventListener(MouseEvent.CLICK,_hander);
            //spr一的侦听器函数不触发了
        }
    }

    public class Test1 extends Sprite
    {
        private var spr:Sprite;
        private var spr2:Sprite;
        public function Test1()
        {
            spr = new Sprite();
            spr.graphics.beginFill(0xff0000,1);
            spr.graphics.drawCircle(100,100,10);
            spr.graphics.endFill();
            this.addChild(spr);
            spr.addEventListener(MouseEvent.CLICK,_hander);
            spr.addEventListener(MouseEvent.CLICK,_hander);
            
            spr2 = new Sprite();
            spr2.graphics.beginFill(0xff0000,1);
            spr2.graphics.drawCircle(200,100,10);
            spr2.graphics.endFill();
            this.addChild(spr2);
            spr2.addEventListener(MouseEvent.CLICK,_hander2);
            
            this.stage.addEventListener(MouseEvent.CLICK,_stageClick);
        }
        private function _hander(evt:MouseEvent):void
        {
            trace("click");
            //舞台将不会收到click事件
            evt.stopImmediatePropagation();
        }
        private function _hander2(evt:MouseEvent):void
        {
            trace("click2");
            //spr.removeEventListener(MouseEvent.CLICK,_hander);
            //spr一的侦听器函数不触发了
        }
        private function _stageClick(evt:MouseEvent):void
        {
            trace("stage_click");
        }
    }

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值