so, there´s a easy way to remove all childs from container like this
while (container.numChildren)
{
container.removeChildAt(0);
}
is there a way to remove stage.eventListener in plural (dont know if im using the word right), something like stage.eventListeners? something like that?
thanks!
No, there isn't. There is no mechanism, at least publicly available, that keeps track of event listeners. However, you could do it yourself.
Basically, you need to keep track of each listener that is added. The easiest way would be to extend the classes you want to do this on and override
addEventListener()
.If extending a class is not an option for you (either because you are using Flash Pro with the timeline or if it's the stage you need to remove all event listeners from), you could manually add it to the Vector each time you add an event listener. It's not quite as simple as the way I described above, but it would still work.
Do note that you should probably add the
useCapture
property to the object that is being saved and check for that as well, but I have honestly never set that property to anything but default so I did not include it in my codeThere is a very easy solution, Robert Penner's phenomenal Signals library. Here is an example:
You can go way beyond this to do parameter passing and all sorts of interesting things. I recommend you check out his blog.
http://flashblog.robertpenner.com
Here is a tutorial on how to get started with AS3 Signals:
http://www.youtube.com/watch?v=wB_sWJ5EgXI
Unfortunately the short answer is that it is not possible. Per default, event dispatchers do not publically keep track of what listeners are registered. So you cannot loop over some list and just remove them all.
You will have to remember the listeners you add yourself.
In FlashPlayer 11,
DisplayObjectContainer
supports aremoveChildren
function that removes all children. So you can replace your while loop withcontainer.removeChildren()
As for removing all eventListeners, there is no built-in method for this. However, you could write something yourself to keep track of all listeners added to a particular object, allowing you to remove them all by looping over the collection.