Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flash as3 check event listener

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?

like image 404
David19801 Avatar asked Mar 01 '11 17:03

David19801


2 Answers

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.

like image 84
Malte Köhrer Avatar answered Sep 20 '22 09:09

Malte Köhrer


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,

like image 23
Tyler Egeto Avatar answered Sep 19 '22 09:09

Tyler Egeto