Jun
12
2010

Two regular errors using externalInterface.addCallback()

The ExternalInterface implements the programming communication between between JavaScript and ActionScript corresponds, the addCallback()method is most widely used, it registers an ActionScript method as callable from the container. Errors will be thrown if the browser is supported or violate the security sandbox,you may refer to the help to solve these frequent issues. Here we will talked about two regular errors when use externalInterface.addCallback().

1. Error: The object does not support this attribute or the method. This is because the ActionScript method is called from the container before it has not been registered successfully. The simple the solution: Call the registered ActionScript function within the JavaScript function to call in the container with call()method.
In this example, if we use <body onload=selectCatalog(1)">, the above Error will be thrown. After register selectCatalog function with the addCallback()method, We add the call("isReady") method to call JavaScript function:isReady() from HTML. Because these two ActionScript methods are executed sequentially, we can call selectCatalog(1) function in isReady() function  without the error.

2. Error: successes in the IE with call addCallback(), but fails in Firefox. This is because the syntax is different when refers to on the swf object. window [movieName] is for IE, but document [movieName] for Firefox. We have to dealt with it separately according to browser. Of course we can use document.getElementById("movieName" ).
in this example, if we use Main.getSongList (data), the above error will be thrown, we use thisMovie() function to solve the issue.

Please View the demo, download the source code.

原文:http://www.riafan.com/article/as/externalinterface-addcallback-two-errors.html

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading