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

Simple button frame navigation in HTML5 stops working

Explorer ,
Jun 29, 2020 Jun 29, 2020

Copy link to clipboard

Copied

I have been trying out simple navigation between two frames (frame 0 and frame 4) with a button. 

 

on the first frame I just have a text and a button with the code:

 

this.stop();

this.btn_scena.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

function fl_ClickToGoToAndStopAtFrame()
{
this.gotoAndStop(4);
}

 

and on frame 4:

 

this.btn_scena.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

function fl_ClickToGoToAndStopAtFrame()
{
this.gotoAndStop(0);
}

 

 

It works for about 10 times and then stops, since I just used Code Snippets and didn't make my own code I'm not sure how this could possibly not work. 

Thanks in advance. 

 

Views

237

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

correct answers 1 Correct answer

Explorer , Jun 30, 2020 Jun 30, 2020

There alredy was only one button with its own layer. 

However you did give me an idea.

For whatever reason, it works if the button has a different instance name in frame 0 and 4. 

Thanks for the help!

 

Votes

Translate

Translate
Community Expert ,
Jun 29, 2020 Jun 29, 2020

Copy link to clipboard

Copied

i'm not sure why it works, at all: the first time frame 4 plays, you have two same named functions and you have two listeners.  ie, the frame 0 function still exists so there should be an error about duplicate functions but animate doesn't detect the error so that's an animate/javascript failing.

 

the other problem (duplicate listeners) is causing the problem with what you probably see which is the responsiveness after clicking gradually slowing with each click because you're executing the frame 0 function 10 times and the frame 4 function 10 times after the tenth time frame 4 plays.

 

anyway, to fix the problem use:

 

this.stop();

this.frame0_executed;

 

if(!this.frame0_executed){

this.frame0_executed=true;

this.btn_scena.addEventListener("click", fl_ClickToGoToAndStopAtFrame_0.bind(this));

}

function fl_ClickToGoToAndStopAtFrame_0()
{
this.gotoAndStop(4);
}

 

and on frame 4:

 

this.frame4_executed;

if(!this.frame4_executed){

this.frame4_executed=true;

}

this.btn_scena.addEventListener("click", fl_ClickToGoToAndStopAtFrame_4.bind(this));

function fl_ClickToGoToAndStopAtFrame_4()
{
this.gotoAndStop(0);
}

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
Explorer ,
Jun 29, 2020 Jun 29, 2020

Copy link to clipboard

Copied

Thank you very much but with that code it works only once. 

It goes from frame 0 to frame 4 and back to 0 but stops working after that. 

It seems that the event listener stops working properly for some reason. That would explain why it did kind of work before.

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 Expert ,
Jun 29, 2020 Jun 29, 2020

Copy link to clipboard

Copied

then you must have "different" btn_scena's on frame 0 and frame 4.  to remedy, move btn_scena to its own layer in frame 0 and extend (if needed) its layer to frame 4 with no other keyframes.  remove any other btn_scena's.

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
Explorer ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

There alredy was only one button with its own layer. 

However you did give me an idea.

For whatever reason, it works if the button has a different instance name in frame 0 and 4. 

Thanks for the help!

 

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 Expert ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

LATEST

you're welcome.

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