PDA

View Full Version : Remove all listeners of a given type? (i.e. 'click')



JakeL
30 Mar 2012, 2:36 PM
Hi All -

I have a scenario whereby I'm trying to override previously set listeners on an object, such as a button click. Essentially, after the object (say a button) is created, a security manager comes in later and adds a different event to the button which instead of having the button execute its original purpose, instead alerts a message saying "you can't do that."

To accomplish this, in a generic way, I need to remove the previous listener, or listeners, and add the new one showing the disabled message.

So, I wanted to see if there is a way to remove listeners of a particular type from an event. Something on the order of:



for(<list of various buttons, checkboxes, whatever>)
{
extObject.clearListeners('click'); extObject.addListener("click", this.permissionDenied);
}



It appears that clearListeners removes ALL events, which might be a bit heavy handed - any other listeners would get nuked at that time.

Thanks for any advice,

-Jake

mitchellsimoens
31 Mar 2012, 8:50 AM
You would need to use removeListener or un. clearListeners will just clear all.