2

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){
      //...
   }
}
Breno LarC
  • 104
  • 7

1 Answers1

4

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.

Marcelo Assis
  • 5,136
  • 3
  • 33
  • 54
  • Note: this doesn't actually works very well, when callback wasn't added yet - calling to the method from JS shows "Uncaught TypeError: undefined is not a function" when it was removed with the methods above - it will show "Uncaught Error: Error calling method on NPObject.". So it doesn't work very clean. – Aleksei Apr 04 '15 at 15:37
  • I've try to remove it with this code, but error has appear when web calls removed event: [Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference. at flash.external::ExternalInterface$/_callIn() – Selirion Apr 08 '16 at 09:48