removeEventListener extension?

Okay, I have to admit that I’m very puzzled as to why this isn’t a native method in Actionscript3.

Either way, I was wondering if anyone had any tips on how to create something like;

clip.removeAllEventListeners();

Ie: something that will clear all listeners without having to specify them one by one with event and callback specified.

Any feedback is appreciated.

Senoculars response makes some sense, but I can’t say I understand exactly what he means by it.

Basically you have to make your own version of addEventListener for whatever object you’re adding listeners to. This method, when called, will catalog the arguments passed (the first 3 represent the signature for the event) and save those for a later time to be called in removeEventListener for removal while calling the original addEventListener to make sure the listener is actually added.

Once you want to remove them all, run through your signature list and call the arguments against removeEventListener.

The reason this isn’t native is because you shouldn’t be allowed to muck up any other processes that are using any targeted listener for functionality. For example, there could be any number of classes which rely on the stage for events. If you haphazardly create some process that removes all listeners from the stage object, you could break your entire movie. :wink:

Great, thanks Senocular.

Might be inefficient but this way feels more logical to me instead of typing each removeEventListener every time, especially when there’s a couple of them attached to the same object.

Anyway, thanks! I’ll get on it.

I came across this yesterday. [URL=“http://k2xl.com/wordpress/2008/07/02/as3-eventmanager-class-removealllisteners/”]AS3 EventManager Class: removeAllListeners