Search code examples
actionscript-3addcallback

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){
      //...
   }
}

Solution

  • 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.