跨域外部接口“调用 NPObject 方法时出错" [英] Cross Domain ExternalInterface "Error calling method on NPObject"

查看:27
本文介绍了跨域外部接口“调用 NPObject 方法时出错"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过跨域的 ExternalInterface 启用 Javascript 和 Flash 之间的通信.当 Javascript 与 SWF 位于同一域中时,它的效果会很好.但在一种情况下,HTML 驻留在域 A 上,javascript 和 flash 都驻留在域 B 上.我已完成以下所有操作:

I am trying to enable communication between Javascript and Flash via ExternalInterface across domains. The Javascript works great when it is located on the same domain as the SWF. But in one case, the HTML resides on domain A, the javascript and the flash both reside on domain B. I have done all of the following:

  • 嵌入标签具有 allowScriptAccess="always"(并且对象将其作为参数)
  • 我的 SWF 文件的 actioncipt 有 Security.allowDomain("*")
  • 我的 SWF 也调用 Security.allowInsecureDomain("*")
  • 域 A 和域 B 都有一个 /crossdomain.xml 文件,其中包含 allow-access-from domain="*"
  • The embed tag has allowScriptAccess="always" (and the object has that as a param)
  • My SWF file's actionscipt has Security.allowDomain("*")
  • My SWF also calls Security.allowInsecureDomain("*")
  • Both domain A and domain B have a /crossdomain.xml file which has allow-access-from domain="*"

SWF 能够在页面上调用 javascript,但是当我使用 Javascript 调用 ExternalInterface 公开的函数时,我得到

The SWF is able to call javascript on the page, but when I use Javascript to call functions exposed by ExternalInterface, I get

在 NPObject 上调用方法时出错![插件异常:Actionscript 中的错误.使用 try/catch 块查找错误.]

Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.]

这是 ActionScript 2,所以 ExternalInterface.marshallExceptions 不可用.

This is ActionScript 2 so ExternalInterface.marshallExceptions is not available.

推荐答案

你应该只需要两件事就可以了:

You should only need two things for this to work:

1) allowscriptaccess=always 将允许您的 swf 将内容发送到页面

1) allowscriptaccess=always will allow your swf to send stuff out to the page

2) System.security.allowDomain("yourhtmldomain.com");

请注意,它是 AS2 中的 System.security.allowDomain() - 它与 AS3 或您在上面编写的内容不同.

Note that it's System.security.allowDomain() in AS2 - it's not the same as AS3 or what you have written above.

上面的数字 2 允许域 A 上的 html 页面调用域 B 上的 swf 中的内容.

number 2 above allows the html page on domainA to call things in the swf on domainB.

js 所在的域在这里无关紧要,因为浏览器将其嵌入在 domainA 中,脚本在 domainA 中执行.

The domain your js is hosted on won't matter here, since the browser embeds it on domainA, the script is executed in domainA.

crossdomain.xml 主要仅用于加载远程文件,您不会这样做,因此您可以根据需要将其删除.(并且您可能不希望在您的主域上使用 allow="*" 的 crossdomain.xml 文件,这是非常糟糕的做法)

crossdomain.xml is mainly only for loading remote files, which you aren't doing, so you can remove that if you like. (and you probably don't want to have a crossdomain.xml file with allow="*" sitting on your main domain, that's very bad practice)

这篇关于跨域外部接口“调用 NPObject 方法时出错"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆