Highlighted

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

Explorer ,
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

52

Likes

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

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

Explorer ,
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

53

Likes

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
Oct 11, 2019 0
Adobe Community Professional ,
Oct 14, 2019

Copy link to clipboard

Copied

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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Oct 14, 2019 0