码迷,mamicode.com
首页 > 其他好文 > 详细

as3 阻止后续侦听器

时间:2014-11-20 10:16:21      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

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");
        }
    }

 

 

as3 阻止后续侦听器

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/as3lib/p/4109866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!