JavaScript -> Flash 抛出“在 NPObject 上调用方法时出错”
我正在尝试从 Javascript 调用 Flash (AS3) 函数。当代码运行时,我收到错误“错误:未捕获的异常:在 NPObject 上调用方法时出错!”从我一天的谷歌搜索来看,这似乎是一个安全问题,我已经做了我能找到的一切,但错误仍然出现。
一些细节:
* Flash 9 和 Flash 10 播放器都会出现这种情况。
* swf 与加载它的 php 文件位于同一域中,并且该文件包含尝试调用 Flash 函数的 javascript。
* 我使用 sfwobject2.2 加载 swf 文件,如下所示:
<代码> var flashvars = {};
var 参数 = {};
var params = {menu: false, bgcolor: "#ffffff", allowedScriptAccess: "always"};
swfobject.embedSWF("/path/to/swf", "id", "480", "310", "9.0.0", null, flashvars, params, 属性);
据我所知,我的 Flash 影片正在正确执行 allowedDomain 操作:
<代码> Security.allowDomain("www.mydomain.com");
* 我知道ExternalInterface.addCallback设置正确——当我禁用它时,我得到一个“没有这样的函数”错误,而不是NPObject投诉。
这让我完全发疯,我就是不知道如何纠正它。有什么建议吗?
I'm trying to call a Flash (AS3) function from Javascript. When the code runs, I get the error "Error: uncaught exception: Error calling method on NPObject!" From my day's worth of googling around, this seems to be be a security matter, and I've done everything I can find, but the error still comes up.
Some details:
* This happens with both Flash 9 and Flash 10 players.
* The swf is in the same domain as the php file that loads it and that contains the javascript that's trying to call the Flash function.
* I'm using sfwobject2.2 to load the swf file, like so:
var flashvars = {};
var params = {};
var params = {menu: false, bgcolor: "#ffffff", allowScriptAccess: "always"};
swfobject.embedSWF("/path/to/swf", "id", "480", "310", "9.0.0", null, flashvars, params, attributes);
My Flash movie is doing the allowDomain thing, correctly as far as I can tell:
Security.allowDomain("www.mydomain.com");
* I know that the ExternalInterface.addCallback is set up properly -- when I disable it, I get a "no such function" error instead of the NPObject complaint.
This is driving me completely crazy, and I just can't figure out how to correct it. Any advice out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现的答案是,由于多种原因,它会引发该错误。我的问题是我没有为它所调用的函数发送正确数量的参数。
The answer I found was that it throws that error for many reasons. Mine was that I was not sending in the correct number of arguments for the function it was calling.
我发现通过从 Adobe 网站安装 Flash 播放器的调试版本,我会得到一个对话框,其中包含实际的 Flash 异常,而不是 NPObject 错误,因此这可能是了解实际情况的有用的第一步在。
就我而言,看起来不知何故,传递的参数数量不正确,而且我不确定这是如何发生的(间歇性地),但这是另一个问题。 :)
I found that by installing the Debugging version of the flash player from Adobe's site, I'd get a dialog box with the actual flash exception in it instead of the NPObject error, so this might be a helpful first step in figuring out what's actually going on.
In my case it looks like somehow, there is an incorrect number of arguments getting passed, and I'm not sure how this is happening (intermittently), but that's for another question. :)