Copy link to clipboard
Copied
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!
use:
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);
Copy link to clipboard
Copied
use:
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);
Copy link to clipboard
Copied
thanks! its right!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
yes, thank you
Copy link to clipboard
Copied
I am Spartacus.
Copy link to clipboard
Copied
I am Spartacus.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now