加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash – as3 removeEventListener无法正常工作

发布时间:2020-12-15 07:25:12 所属栏目:百科 来源:网络整理
导读:这真让我抓狂.为什么removeEventListeners不起作用? 类构造函数 public function item(brand:String,title:String,price:Number,mp:Number,path:String,sb1:*,sb2:*):void sb1:*和sb2:*是对象挂钩. 这些是指定的听众: _sb1.addEventListener("Changed",s
这真让我抓狂.为什么removeEventListeners不起作用?

类构造函数

public function item(brand:String,title:String,price:Number,mp:Number,path:String,sb1:*,sb2:*):void

sb1:*和sb2:*是对象挂钩.

这些是指定的听众:

_sb1.addEventListener("Changed",slideBarChanged); // Price
_sb2.addEventListener("Changed",slideBarChanged); // MegaPixels

这个函数叫做:

private function slideBarChanged(e:Event):void
{           
switch(e.target.type)
{
    case "Price": 
        if(int(e.target.currVal) > Math.abs(this.price))
        {
            this._active = false;
            _sb2.removeEventListener("Changed",slideBarChanged);
        }
        else {
            this._active = true;
            _sb2.addEventListener("Changed",slideBarChanged);
        }
        break;

    case "MegaPixels": 
        if(int(e.target.currVal) > Math.abs(this.mpixels))
        {
            this._active = false;                           
            _sb1.removeEventListener("Changed",slideBarChanged);
        }
        else { 
            this._active = true;
            _sb1.addEventListener("Changed",slideBarChanged);
        }
        break;          
}

Everthing工作,但当项目变为_active = false时,不会删除侦听器;
实际上,这应该像这样工作:

如果价格太高,则忽略百万像素,只听取价格.
如果百万像素太高,则忽略价格,只听百万像素.

打破我的大脑,非常感谢任何帮助.
感谢名单.

解决方法

尝试

e.target.removeEventListener("Changed",slideBarChanged);

而不是

_sb1.removeEventListener("Changed",slideBarChanged);

要么

_sb2.removeEventListener("Changed",slideBarChanged);

另外,在单独的注释中,您应该为addEventListener()和removeEventListener()方法的type参数解析常量而不是字符串文字.

const CHANGED:String = "changed";

_sb1.addEventListener(CHANGED,slideBarChanged); 
_sb1.removeEventListener(CHANGED,slideBarChanged);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读