Skip to main content
Participating Frequently
July 18, 2016
Question

remove event listeners

  • July 18, 2016
  • 2 replies
  • 579 views

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();

}

This topic has been closed for replies.

2 replies

robdillon
Participating Frequently
July 19, 2016

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.

krakk356Author
Participating Frequently
July 19, 2016

yes is exactly that, a quiz game

krakk356Author
Participating Frequently
July 19, 2016

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.

Ned Murphy
Legend
July 18, 2016

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?

krakk356Author
Participating Frequently
July 19, 2016

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.

Ned Murphy
Legend
July 19, 2016

Show the code you tried to use in the goP4 function... show it in the function the way you tried it.