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

How can I stops actions/code at a certain frame?

Explorer ,
Oct 11, 2019 Oct 11, 2019

Copy link to clipboard

Copied

So I have a fairly simple HTML5 project going with basic button navigation.  I navigate to one section, then back to the main menu, then to other sections etc.  I'm finding that when I launch the project and go to any given section of it, it works fine.  But when I go back and forth between the main section and other sections it gets increasingly more glitchy.

 

My best guess is that everytime I return to the first frame I'm retriggering the code there, which is conflicting with the code that is already 'running' if that makes sense.  What I think will solve the problem is if I add a line of code on the first frame that will end all currently active event listeners so that the code is essentially restarting fresh every time the user returns to the main menu to avoid any conflicting actions.

 

I'm pretty sure I've seen this done, and may have even done it myself at some point but I don't remember how to do it and I can't find a tutorial or example of it online.

 

Please help!

 

Thanks!

Views

135

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 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

LATEST

Hi.

 

Yeah. You're right. When you revisit frames, code is run again if you don't do some check. In your case, probably you keep re-adding listeners.

 

One easy way to avoid this is to check if the current frame is running for the first time by checking a custom property. For example:

 

var root = this;

if (root.frame0Started)
{
    root.yourButton.on("click", root.yourEventHandler);
    root.frame0Started = true;
}

 

I hope this helps.

 

 

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