Skip to main content
Participating Frequently
January 2, 2024
Answered

Animate HTML5 Movie Clip Sending Too Many Browser Alerts

  • January 2, 2024
  • 2 replies
  • 360 views

I am using Adobe Animate to make a video with two types of navigation in html5 canvas. One of the two types seems faulty and activates multiple times for an unknown reason. For background, I have a main timeline with navigation and a menu panel (specified as a movie clip) within the main timeline which has its own internal timeline navigation properties.


My basic navigation functions on the main timeline are like the following:

this.back_btn.addEventListener("click", MoveBackMain.bind(this));

function MoveBackMain(){
if (this.currentFrame > 2){this.gotoAndStop(this.currentFrame-1);
document.getElementById('PageText').value = String(this.currentFrame-1);}
else {alert('You are at the beginning');}
}

This works fine. When I get to the beginning, I get a single notice that I am at the beginning. There is a similar type of notification with my forward button that give me a single notice when I reach the end.


Within the menu, however, I have more issues with the timeline. I made the menu into a movie clip so that I could specify different pages of options on the timeline. I want the user to know when they are at the beginning of the options and when they are at the end. All of the buttons in the menu have different instance names than the buttons on the main timeline. The menu’s code’s structure is very similar:

 

var =  framenmr
framenmr =0

this.menu_back_btn.addEventListener('click', MoveBackMenu.bind(this));
function MoveBackMenu(){ 
if (framenmr > 0){this.gotoAndStop(framenmr-1);
framenmr = framenmr-1;} else {
alert('This is the first page of options.');}
}


This works fine the first time I access the menu and navigate through its timeline, but after the first time, if I go forward and then back again, then I get two consecutive browser alerts. If continue navigating after this and repeat the process, then I get three consecutive browser alerts. The number of alerts that I get keeps increasing the more I navigate back and forth through the menu, but this is never an issue on the main timeline.


Does anyone know why movie clip seems to keep track of how many times I have navigated back and forth and how to stop this behavior?

This topic has been closed for replies.
Correct answer kglad

use an if-statement to make sure button listeners are only addrd once.

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 2, 2024

use an if-statement to make sure button listeners are only addrd once.

Participating Frequently
January 3, 2024

Thank you very much for pointing me in the right direction. The event was being called multiple times, so adding a statement to unbind "this" did the trick which also allowed me to simplify the code (I could finally remove the framenmr variable).

function MoveBackMenu(){
	if (this.currentFrame > 0){this.gotoAndStop(this.currentFrame-1);
		} else {alert('This is the last page of options.');}
	this.menu_back.removeEventListener(MoveBackMenu.unbind(this));
}

 

kglad
Community Expert
Community Expert
January 3, 2024

you're welcome.

 

for others, use

 

if(!this.alreadyExecuted){
this.alreadyExecuted=true;

// add listener and/or any other code

}

Nancy OShea
Community Expert
Community Expert
January 2, 2024

[Moderator moved from Using the Community forums to Animate.]

 

Nancy O'Shea— Product User & Community Expert