简体   繁体   中英

How can I remove an addCallback?

I have a Flash game which send and receive lot of messages from JavaScript. Sometimes I need to stop listening some of those functions, but ExternalInterface doesn't have a removeCallback function. So I'm doing somthing ugly: using a boolean to validate if a callback is available in each function.

Any better solution?

ExternalInterface.addCallback("callAlert", callAlert);
function callAlert(msg:String){
   if(callAlertAvailable){
      //...
   }
}

Just call again addCallback, setting the function as null:

ExternalInterface.addCallback("callAlert", null);

Why not read the docs? I found it here:
ExternalInterface.addCallback()

Note: Repeating addCallback() on an existing callback function with a null closure value removes the callback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM