Is there a way to determine which event listeners are registered with a display object? I want to remove all event listeners from a display object so that I can assign new ones
back2dos has mentioned the approach you should use, what i did was extend the movieclip class and implemented all kinds of functions that i use on daily basis but are not part of the movieclip class. including the override for the addEventListener class
protected var listeners : Dictionary = new Dictionary();
override public function addEventListener( type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = true) : void
{
var key : Object = {type:type,useCapture:useCapture};
if( listeners[ key ] ) {
removeEventListener( type, listeners[ key ], useCapture );
listeners[ key ] = null;
}
listeners[ key ] = listener;
super.addEventListener( type, listener, useCapture, priority, useWeakReference );
}
protected function removeListeners () : void
{
try
{
for (var key:Object in listeners) {
removeEventListener( key.type, listeners[ key ], key.useCapture );
listeners[ key ] = null;
}
}catch(e:Error){}
}