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

remove event listeners

Community Beginner ,
Jul 18, 2016 Jul 18, 2016

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

}

TOPICS
ActionScript
520
Translate
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
LEGEND ,
Jul 18, 2016 Jul 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?

Translate
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 Beginner ,
Jul 19, 2016 Jul 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.

Translate
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
LEGEND ,
Jul 19, 2016 Jul 19, 2016

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

Translate
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 Beginner ,
Jul 21, 2016 Jul 21, 2016

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

}

Translate
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
LEGEND ,
Jul 21, 2016 Jul 21, 2016
LATEST

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.

Translate
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
LEGEND ,
Jul 18, 2016 Jul 18, 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.

Translate
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 Beginner ,
Jul 19, 2016 Jul 19, 2016

yes is exactly that, a quiz game

Translate
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 Beginner ,
Jul 19, 2016 Jul 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.

Translate
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