AS3: removing EventListeners without knowing the number or names
First, a short summary of how my site works: When the link is clicked, it checks that something is already displayed on the left or right side of the screen (the website looks like a book, so I have a left page where I want to display information and the right page). If there is already something showing that it hides it and displays a new object, along with it, it includes all the buttons inside that object (I have separate functions to customize each object).
An example of such an EventListener would be:
pathTo.Button1.addEventListener(MouseEvent.CLICK, function():void {showText(side, object)});
What I am trying to do is remove all previously installed EventListeners without having to create separate functions to remove references within each object.
Shorter version: How to remove all EventListeners for all objects inside another object? The only variable I want to store is the object containing everything. However, objects don't always have EventListeners.
a source to share
Yes it is possible and the solution is here: http://blog.andregil.net/2010/01/how-to-remove-event-listeners-with-parameters-closure/
You can use this snippet for a listener function to remove it from yourself:
event.currentTarget.removeEventListener(event.type, arguments.callee);
;)
a source to share
In the Flex framework, you can run some monkey patch to enable this functionality.
Doug McCune describes how to do this in this blog post .
Edit: Confuse your question a bit. As described, this only works for Flex components. Not sure if you can use the same technique for generic Flash components. Unfortunately.
a source to share