Copy link to clipboard
Copied
Good morning, afternoon, and evening to you all!
The issue that I'm having seems silly. Please bear with me.
I have simple gotoAndStop(); buttons on this project I'm working on. On my title page, I have three of them, and on the pages corresponding to those buttons, I have but one button each; that's my back button, which is a simple gotoAndStop(1); button that executes when clicked. However, when I click on either one of my back buttons, the rest of my buttons simply stop working. Do I need to add my event listeners again?
My code:
public function main()
{
start_btn.addEventListener(MouseEvent.CLICK, clicker);
controlbtn.addEventListener(MouseEvent.CLICK, ctrls);
creditbtn.addEventListener(MouseEvent.CLICK, credit);
bacnbtn.addEventListener(MouseEvent.CLICK, back);
}
function ctrls(e:MouseEvent)
{
gotoAndStop(10);
}
function credit(e:MouseEvent)
{
gotoAndStop(9);
}
function clicker(e:MouseEvent)
{
gotoAndStop(2);
StartLevel();
}
function back(e:MouseEvent)
{
gotoAndStop(1);
}
Help? I need this fixed TODAY ASAP. Please.
Copy link to clipboard
Copied
Are you assigning all this code on frame 1? If so, if you go back to frame 1 you're piling on even more assignments and function definitions over and over.
You should assign the code in frame 1 and then start your while timeline on frame 2. Return back to that (e.g. gotoAndStop(2)) so you never re-run the same code again. Otherwise update the logic so it only runs once.
e.g. on frame 1:
if (!firstRun)
{
// now on thsi frame this var exists forever and the code to assign never runs again
var firstRun:Boolean = true;
// I took 'public' off this as none of the other functions have
// "class" specific access modifiers.. add it back if you're showing
// a mix of class scripting and frame scripting
function main()
{
start_btn.addEventListener(MouseEvent.CLICK, clicker);
controlbtn.addEventListener(MouseEvent.CLICK, ctrls);
creditbtn.addEventListener(MouseEvent.CLICK, credit);
bacnbtn.addEventListener(MouseEvent.CLICK, back);
}
function ctrls(e:MouseEvent)
{
gotoAndStop(10);
}
function credit(e:MouseEvent)
{
gotoAndStop(9);
}
function clicker(e:MouseEvent)
{
gotoAndStop(2);
StartLevel();
}
function back(e:MouseEvent)
{
gotoAndStop(1);
}
}
Now upon returning to frame 1 functions won't be redefined (erroring) nor will assignments be added to buttons that already have them.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now