AS3: Removing EventListeners without knowing amount or names

actionscript-3event-listenerflash

First shortly about how my site works:
When a link is clicked it checks if something is already displayed in either the Left or Right side of the screen (the website looks like a book, so I have a left page I want to display information on and a right page). If there is already something showing it hides it and displays the new object, together with this it enables all the buttons within that object (I have separate functions to set up each object).

An example of such an EventListener would be:

pathTo.Button1.addEventListener(MouseEvent.CLICK, function():void {showText(side, object)});

What I'm trying to do is to remove all the previous set EventListeners without having to create separate functions for removing the links inside every object as well.

Shorter version: How do I remove all EventListeners on all objects inside another object? The only variable I want to store is the object containing everything. There are however not always EventListeners within the objects.

Best Answer

you can check for existing event listeners using

hasEventListener(Event.TYPE)

and you can remove event listeners using

removeEventListener(Event.TYPE, listenerFunc)

Note that you MUST have a reference to the listenerFunc to remove the event listener.

Related Topic