Copy link to clipboard
Copied
Hi everyone
So I have an animation which has several frames. There is some code using drag and drop in a certain frame (say frame number 100). Finally, there is a replay button, clicking on which takes the user back to the first frame (There is simply a 'this.gotoAndPlay(5)' attached to the event listener of this replay button).
This is where all the problems begin.
There is a part of code on frame number 100 which involves 'if' and 'else'. Everything works fine the first time the frame is played.
However, when, after pressing the replay button, the frame is played again, the part of code inside the 'else' block is executed even when the part inside the 'if' block is executed!!
In general, going back to previous frames create lots of troubles. Things that work perfectly while the frame is being played first time simply defy logic when being replayed.
Any help would be appreciated!
Copy link to clipboard
Copied
Hi.
In HTML5 Canvas documents, when revisiting frames with code that should run only once, it's a good idea to create a custom boolean flag. Like this:
if (!this.frame0Started)
{
this.yourButton.on("click", this.doSomething);
this.frame0Started = true;
}
In the example above, the click listener will be added only once to the button no matter how many times the frame is replayed.
Maybe in your case you have code that shouldn't be running more than once.
If that's not the case, please let us know exactly what you are trying to do.
Regards,
JC
Copy link to clipboard
Copied
Thanks for the response. Let me now elaborate.
This piece of code (with if and else) is inside a callback function, say onMouseUp.
Its actually a piece of code that is associated with drag and drop operations.