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

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

问题描述

我试图通过域之间的ExternalInterface启​​用Javascript和Flash之间的通信。当它位于与SWF相同的域时,Javascript效果很好。但在一个例子中,HTML驻留在域A上,javascript和flash都驻留在域B上。我完成了以下所有操作:


  • 嵌入标记包含 allowScriptAccess =always(并且该对象具有作为参数)
  • 我的SWF文件的actionscipt Security.allowDomain(*)

  • 我的SWF也调用 Security.allowInsecureDomain(* )

  • 域A和域B都有一个 /crossdomain.xml 文件,其中<$ c

    $允许访问从域=*

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


在NPObject上调用方法时出错! [插件异常:在脚本错误。使用try / catch块来查找错误。]

这是ActionScript 2的 ExternalInterface.marshallExceptions code>不可用。

解决方案

b
$ b

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

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



请注意AS2中的 System.security.allowDomain() - 与AS3或上面写的不一样。



number 2 above允许domainA上的html页面调用domainB上的swf。



您的js托管的域名在这里无关紧要,因为浏览器将它嵌入到domainA中,脚本在domainA中执行。


$ b

crossdomain.xml主要只用于加载远程文件,这是你没有做的,所以你可以删除如果你喜欢。 (你可能不希望有一个crossdomain.xml文件,其中包含 allow =*坐在你的主域名上,这是非常糟糕的做法)


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:

  • 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="*"

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

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

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

解决方案

You should only need two things for this to work:

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

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

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

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

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 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天全站免登陆