Copy link to clipboard
Copied
hi, i have 5 buttons, only one is the correct and leads to the next frame, the others shows a wrong message,
the problem is, in the next frame, i wanted to do all the same but change one button, but i cant remove the event listeners of the code from the previous frame,
i look many forums and videos, and all the code i tried didn't work,
wonder if someone could help, heres the code:
stop();
ex1.stop();
ex2.stop();
ex3.stop();
ex4.stop();
ex5.stop();
//p1
p1.addEventListener(MouseEvent.CLICK, goP1);
function goP1(event:MouseEvent):void
{
ex1.play();
}
//p2
p2.addEventListener(MouseEvent.CLICK, goP2);
function goP2(event:MouseEvent):void
{
ex2.play();
}
//p3
p3.addEventListener(MouseEvent.CLICK, goP3);
function goP3(event:MouseEvent):void
{
ex3.play();
}
//p4
p4.addEventListener(MouseEvent.CLICK, goP4);
function goP4(event:MouseEvent):void
{
Object(root).gotoAndStop(12)
}
//p5
p5.addEventListener(MouseEvent.CLICK, goP5);
function goP5(event:MouseEvent):void
{
ex5.play();
}
Copy link to clipboard
Copied
What have you tried? What code did you use when you tried? Did you try adding the removals just before the gotoAndStop(12) line in the goP4 function?
Copy link to clipboard
Copied
i've tried the removeEventListener in that line (goP4 function), but did not work. The same buttons on the next frame still do what the code from the previous frame tells.
What i wanted is to change the funtion of some buttons in each frame, but they are the same buttons - one should move to next frame, the others don't.
Copy link to clipboard
Copied
Show the code you tried to use in the goP4 function... show it in the function the way you tried it.
Copy link to clipboard
Copied
I believe i did it, heres the code:
ps: the first time i haven't tell the p1. before de removeEvent, that was why it didn't work.
thanks for the support!
//p4
p4.addEventListener(MouseEvent.CLICK, goP4);
function goP4(event:MouseEvent):void
{
Object(root).gotoAndStop(11)
p1.removeEventListener(MouseEvent.CLICK, goP1);
p2.removeEventListener(MouseEvent.CLICK, goP2);
p3.removeEventListener(MouseEvent.CLICK, goP3);
p4.removeEventListener(MouseEvent.CLICK, goP4);
p5.removeEventListener(MouseEvent.CLICK, goP5);
}
Copy link to clipboard
Copied
Yes, if you neglected to target the object that has the listener then you will not be doing anything to that object.
You should put the removals before you change frames, just to be sure it happens before you move.
Copy link to clipboard
Copied
Can you explain in more detail what you are trying to achieve? From your description it looks like you are building a game or a quiz of some sort and you want to move the user from one frame to another depending on the choice the user makes.
Copy link to clipboard
Copied
yes is exactly that, a quiz game
Copy link to clipboard
Copied
for example, on the next frame, all the code should be the same, the only change is that the p4 plays the ex4 and the p1 does the root to the next frame.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now