Interaction between JavaScript and SwF on webpages

Source: Internet
Author: User
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 ("*");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.