How can I remove an addCallback?

1.4k views Asked by At

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

There are 1 answers

2
Marcelo Assis On BEST ANSWER

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.