简体   繁体   English

事件侦听器曾经在HTML5 Canvas中的CreateJS / Animate CC中成倍增加火灾

[英]event listeners ever multiplying fires in CreateJS / Animate CC in the HTML5 Canvas

Animate CC, HTML5 Canvas. 动画CC,HTML5画布。 I have an animation with several clickthrough exits, to twitter, facebook etc. The animation has a repeat button. 我有一个动画,其中有几个点击后到达出口,可以到达Twitter,Facebook等。该动画有一个重复按钮。 On the first play-through when I click the twitter exit just one twitter page opens, on the 2nd play through I click the same exit button and it opens TWO twitter pages, (and so on ad-infinitum. If I clicked repeat 50 times if would open 50 twitter pages :) ). 在第一个播放中,当我单击Twitter退出时,仅打开一个Twitter页面,在第二个播放中,我单击相同的退出按钮,并打开两个Twitter页面,(依此类推,以此类推。如果单击,重复50次)如果将打开50个Twitter页面:))。

Here's one code snippet from frame 342: 以下是第342帧的一个代码段:

root.twBtn.addEventListener("click", fl_MouseOverHandler_2.bind(this));

var frequency = 3;
stage.enableMouseOver(frequency);

function fl_MouseOverHandler_2(){
    window.open(clickTag1, "_blank");
}

I tried removing the event listener (in the replay function) on that same frame, and I'm still getting the same thing happening, this +1 of windows opening each time clicktag1 etc is fired after replaying the ad. 我尝试在同一帧上删除事件侦听器(在重播功能中),但我仍然遇到相同的情况,在重播广告后每次触发clicktag1等时打开的+1窗口。 How can I fix this? 我怎样才能解决这个问题? I'm not sure if the event listener is actually being removed, or what is happening. 我不确定事件监听器实际上是被删除还是正在发生。

// Replay
root.reBtn.on("click", function(evt){
    root.twBtn.removeEventListener("click", fl_MouseOverHandler_2);
    root.gotoAndPlay("start");
});

Basically my listeners are firing +1 times each time I replay the animation. 基本上,每次重播动画时,我的听众都会发射+1次。 I tried the solution here and it didn't work in my situation. 我在这里尝试了该解决方案,但在我的情况下不起作用。 How can I fix this? 我怎样才能解决这个问题?

Ok I solved it. 好的,我解决了。

I added root.x = 1; 我添加了root.x = 1; on Animate CC Frame 1 (createjs's frame 0) , the banner replays from Animate CC Frame 2 (createjs's frame 1) (so it never plays the frame root.x is originally defined in again), and I switched out the eventlistener code for the following, wrapped in an if statement testing root.x . 在Animate CC框架1 (createjs's frame 0) ,横幅从Animate CC框架2 (createjs's frame 1)重放(因此它再也不会播放框架root.x最初是在此定义的),并且我将root.x器代码切换为接下来,包裹在测试root.xif语句中。 It works for me. 这个对我有用。

if (root.x === 1){
root.twBtn.on("click", function(evt){
    window.open(clickTag1, "_blank");
    y=y+1;  
    })
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM