JavaScript and SwF can interact with each other on a webpage in the following situations:
1.swf and the called JavaScript are in the same domain
2.swf and the called JavaScript are in different domains, such as loading remote SWF and then calling services in other regions
For the SWF cross-origin call service, you can solve the problem through the crossdomain. xml configuration.
However, for loading remote SWF, by default, you cannot register the method in it as a method that is made public to Javascript. This type of error is generally reported:
A) securityerror:Error#2060: Security Sandbox conflict: externalinterface. The caller remote.com/test.swf (the mounted remote SWF) cannot access 127.0.0.1 (a service on the local machine)
At flash. External: externalinterface $/_ initjs ()
At flash. External: externalinterface $/addcallback ()
...
B) error: uncaught exception:Error Calling Method On Npobject! [Plugin exception:ErrorIn ActionScript. Use a try/Catch Block to findError.]
Solution
The A error occurs because the remote SWF is not authorized to access the current HTML document after being loaded locally. For this error, you only need to set the allowScriptAccess attribute when outputting the SWF, which is generally set to always..
The error B is caused by the fact that the method is not allowed to be registered to HTML documents of different domains in the default ActionScript. You only need to add the code in as to solve this problem:
Import flash. system. Security;
Security. allowdomain ("*");
Security. allowinsecuredomain ("*");