Is their a way to check if an event listener already exists to remove it?
stage.addEventListener(MouseEvent.CLICK, clickdownfunction);
Basically, I want to remove the listener, but sometimes it has already been removed, so I want to check if it exists and if it does, then remove it.
Is this possible?
Check out the hasEventListener()
function from
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/IEventDispatcher.html#hasEventListener()
I am not really sure though why you want to do that check. Removing non existant listeners won't make Flash drop exceptions or errors, thus the check is just adding unneccessary overhead.
you can't check if a specific function is registered as a listener, you can though check if a type is registered. This can be done with this:
hasEventListener(type:String):Boolean
Alternatively you can just call removeEventListener
, if it's not registered it'll just ignore the call.
Hope that helps,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With