0

Ex: The variable something is a random sprite

something.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(e:MouseEvent)
{
    //Now I want to remove the eventlistener from something
}

How can I do that in AS3?

Erik W
  • 2,590
  • 4
  • 20
  • 33

1 Answers1

4
something.removeEventListener(MouseEvent.CLICK, clickHandler);

or if something is a local variable or you use this handler for multiple sprites:

e.currentTarget.removeEventListener(MouseEvent.CLICK, clickHandler);

docs

Crabar
  • 1,829
  • 1
  • 14
  • 26
  • What is the difference between e.target and e.currentTarget? – Erik W Dec 30 '14 at 15:28
  • 1
    Answer on this question is not so simple... It hard to me to explain this in this comment. I recommend you to read this article for better understanding "event flow" - http://www.actionscript.org/resources/articles/860/1/Understanding-the-AS3-Event-Flow/Page1.html. In two words: currentTarget will be always that object that you use with "addEventListener". But target maybe its parent or child. – Crabar Dec 30 '14 at 15:34
  • I also found this http://stackoverflow.com/questions/5921413/difference-between-e-target-and-e-currenttarget – Erik W Dec 30 '14 at 15:35
  • 1
    Yep, this is explanation is also right. More wide then mine, but much shorter then article that I linked before =) – Crabar Dec 30 '14 at 15:37