zoukankan      html  css  js  c++  java
  • 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");
            }
        }
    
    
    
     
  • 相关阅读:
    No.5 Verilog 建模方式
    No.1 Verilog HDL简介
    [好文推荐]能大大提升工作效率和时间效率的9个重要习惯
    org.apache.commons.net.ftp.FTPClient上传文件大小改变的解决方法
    利用myeclipse建立webservice服务端和客户端
    FtpClient.storeFile返回false解决方法
    jquery表单formSerialize方法乱码问题解决
    Apache FTPClient下载地址
    Myeclipse发生java heap space错误
    UtraEdit的下载地址,无需注册码的
  • 原文地址:https://www.cnblogs.com/as3lib/p/4109866.html
Copyright © 2011-2022 走看看