Skip to main content
Inspiring
June 18, 2018
Answered

removeEventListener in another timeline frame for html canvas

  • June 18, 2018
  • 1 reply
  • 693 views

Hi!

I really do not know the advice. I work with Adobe Animate canvas. I need to turn on the eventlistener inside the movieclip in frame 2 of its timeline, and turn it off in frame 3 of its timeline. On frame 3 I go through the canvas button. But the removeeventlistener works only in the frame where the listener was defined.

In frame 2 I have this code:

aliasRozne = Rozne.bind (this);

this.addEventListener ("tick", aliasRozne);

function Rozne ()

{

     frame = frame + 1

     if (frame == 50)

     {

          this.svetlo1.visible = true;

     }

     if (frame == 250)

     {

          this.svetlo5.visible = true;

          this.removeEventListener ("tick", aliasRozne);

     }

}

In frame 3 I have this code:

this.removeEventListener ("tick", aliasRozne);

But the listener does not turn off in frame 3 and frame is still increasing. When I stay on frame 2, everything is ok.

Do you have any advice?

Thanks!

This topic has been closed for replies.
Correct answer kglad

use:

user

this.aliasRozne = Rozne.bind (this);

this.addEventListener ("tick", this.aliasRozne);

function Rozne ()

{

     frame = frame + 1

     if (frame == 50)

     {

          this.svetlo1.visible = true;

     }

     if (frame == 250)

     {

          this.svetlo5.visible = true;

          this.removeEventListener ("tick", this.aliasRozne);

     }

}

In frame 3 I have this code:

this.removeEventListener ("tick", this.aliasRozne);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 18, 2018

use:

user

this.aliasRozne = Rozne.bind (this);

this.addEventListener ("tick", this.aliasRozne);

function Rozne ()

{

     frame = frame + 1

     if (frame == 50)

     {

          this.svetlo1.visible = true;

     }

     if (frame == 250)

     {

          this.svetlo5.visible = true;

          this.removeEventListener ("tick", this.aliasRozne);

     }

}

In frame 3 I have this code:

this.removeEventListener ("tick", this.aliasRozne);

Inspiring
June 18, 2018

thanks! its right!

Legend
June 18, 2018

You really should be using this.frame instead of just frame, which creates a global variable. And I hope you're initializing it, because adding 1 to undefined isn't pretty.