Removing all event listeners in Flex

2019-04-12 12:56发布

问题:

How can I remove all event listeners on all components at once, especially when it is not known what listeners are attached to each component?

回答1:

You can override mx.core.FlexSprite, which UIComponent inherets from, and generate an array of listeners created. Doug Mc Cune put up source code here.

His blog says: removeAllEventListeners() – removes all event listeners of all types. This completely wipes out all event listeners for the component all at once.

Let us know if this does the job!



回答2:

No!

You might be able to mock something up with hasEventListener and willTrigger. But, there doesn't appear to be an obvious way to remove the event listeners without actually knowing the method name.

What do you want to do this for?



回答3:

There is an issue in Adobe JIRA for this task, please vote if you feel that it important for you

https://bugs.adobe.com/jira/browse/SDK-14127



回答4:

Elad Elrom has a post on his implementation to store event listener references, and be able to remove them all at once:

http://elromdesign.com/blog/2010/07/16/easy-way-to-store-event-listeners-reference-prevent-memory-leaks/