• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

If and else both running when replaying a previous frame in animate cc HTML5

Community Beginner ,
Oct 12, 2020 Oct 12, 2020

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!

Views

181

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2020 Oct 13, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 13, 2020 Oct 13, 2020

Copy link to clipboard

Copied

LATEST

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines