Egret社区

[Egret Wing] 事件移除bug

2020-5-23 17:50
4273
产品 Egret Wing 版本 5.2.16
复现概率 100% 平台 Windows win10专业工作站版
复现步骤 进入界面,添加多个监听事件,执行到指定条件后移除事件,
移除后事件还在执行
问题描述 注册6个以上的广播事件后无法移除最后一个广播事件
错误代码 public init() {
this.display = new egret.Shape();
this.parent.addChild(this.display);
for (let i = 0; i < 8; i++) {
this.addEventListener(egret.Event.ENTER_FRAME, this["enterFrameHandler" + i], this)
}

}



private enterFrameHandler0() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree0 * Math.PI / 180)
this.btn0.x = this.centerX + pt.x
this.btn0.y = this.centerY + pt.y
this.degree0 += 5
if (this.degree0 == 360) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler0, this)
}
private enterFrameHandler1() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree1 * Math.PI / 180)
this.btn1.x = this.centerX + pt.x
this.btn1.y = this.centerY + pt.y
this.degree1 += 5
if (this.degree1 == 360 + 45) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler1, this)
}
private enterFrameHandler2() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree2 * Math.PI / 180)
this.btn2.x = this.centerX + pt.x
this.btn2.y = this.centerY + pt.y
this.degree2 += 5
if (this.degree2 == 360 + 90) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler2, this)
}
private enterFrameHandler3() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree3 * Math.PI / 180)
this.btn3.x = this.centerX + pt.x
this.btn3.y = this.centerY + pt.y
this.degree3 += 5
if (this.degree3 == 360 + 135) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler3, this)
}
private enterFrameHandler4() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree4 * Math.PI / 180)
this.btn4.x = this.centerX + pt.x
this.btn4.y = this.centerY + pt.y
this.degree4 += 5
if (this.degree4 == 360 + 180) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler4, this)
}
private enterFrameHandler5() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree5 * Math.PI / 180)
this.btn5.x = this.centerX + pt.x
this.btn5.y = this.centerY + pt.y
this.degree5 += 5
if (this.degree4 == 360 + 225) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler5, this)
}
private enterFrameHandler6() {
let pt: egret.Point = egret.Point.polar(this.radius, this.degree6 * Math.PI / 180)
this.btn6.x = this.centerX + pt.x
this.btn6.y = this.centerY + pt.y
this.degree6 += 5
if (this.degree6 == 360 + 270) this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler6, this)
}
BUG截图

分享到 :
0 人收藏

3 个回复

倒序浏览
app小王子  社区管理员 | 2020-5-25 14:21:37
  1.         this.touchEnabled = true;

  2.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack1,this);
  3.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack2,this);
  4.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack3,this);
  5.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack4,this);
  6.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack5,this);
  7.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack6,this);
  8.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack7,this);
  9.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack8,this);
  10.         this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack9,this);
  11.     }

  12.     private onCallBack1(){
  13.         console.log(1);
  14.         
  15.     }

  16.     private onCallBack2(){
  17.         console.log(2);
  18.         
  19.     }

  20.     private onCallBack3(){
  21.         console.log(3);
  22.         
  23.     }

  24.     private onCallBack4(){
  25.         console.log(4);
  26.         
  27.     }

  28.     private onCallBack5(){
  29.         console.log(5);
  30.         
  31.     }

  32.     private onCallBack6(){
  33.         console.log(6);
  34.         
  35.     }

  36.     private onCallBack7(){
  37.         console.log(7);
  38.         
  39.     }

  40.     private onCallBack8(){
  41.         console.log(8);
  42.         
  43.     }

  44.     private onCallBack9(){
  45.       
  46.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack1,this);
  47.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack2,this);
  48.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack3,this);
  49.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack4,this);
  50.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack5,this);
  51.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack6,this);
  52.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack7,this);
  53.         this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onCallBack8,this);
  54.       
  55.         
  56.     }
复制代码

app小王子  社区管理员 | 2020-5-25 14:22:41

写了个简单demo测试了一下 ,移除侦听器没有问题。你的业务代码是不是有问题?最好上传附件。你贴的代码片段我无法运行
Egret_RootUser  初学乍练 | 2020-7-22 18:30:23

非常感谢  当初是我的代码逻辑有问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Egret_RootUser

初学乍练

积分: 4 帖子: 3 精华: 0

楼主热帖

小黑屋|京网文[2014]0791-191号|京ICP证150115号|Egret社区 ( 京ICP备14025619号 )

Powered by Discuz! X3.4 © 2001-2019 Comsenz Inc.

返回顶部