jQuery 未捕获的错误:在 NPObject 上调用方法时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8936795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught Error: Error calling method on NPObject
提问by AnApprentice
I have a flash video on my page as follows:
我的页面上有一个 Flash 视频,如下所示:
<script type="text/javascript">
var flashvars = {
};
var params = {
movie: "VideoMain.swf",
quality: "high",
bgcolor: "#000000",
allowScriptAccess: "always",
wmode: "transparent"
};
var attributes = {
id: "VideoMain",
name: "VideoMain",
classid: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
width: "100%",
height: "100%"
};
swfobject.embedSWF("./video/VideoMain.swf", "myVideoContent", "100%", "100%", "11.0.0","", flashvars, params, attributes);
</script>
<div id="myVideoContent">
<h1>Oooppsss....you need flash or a newer version of flash</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
The above gets appended into #VideoMain
以上内容附加到#VideoMain
Then I have the following:
然后我有以下内容:
$('#X.click').click(function(e) {
var flash = document.getElementById("VideoMain");
flash.sendToActionScriptPublishVideo(true);
});
This fails with the console error:
这失败并出现控制台错误:
Uncaught Error: Error calling method on NPObject.
(anonymous function)
jQuery.event.dispatchjquery.js:3256
jQuery.event.add.elemData.handle.eventHandlejquery.js:2875
Any ideas what could be wrong here? Thanks
任何想法这里可能有什么问题?谢谢
回答by
NPObjectis an "interface" to any "foreign" code exposed through the browser (foreign, as in foreign to JavaScript, otherwise it may be browser's own objects, like the global window object for example). The embedded Flash plugin would certainly implement this "interface" (so the browser sees it as just another NPObject).
NPObject是通过浏览器公开的任何“外部”代码的“接口”(外部代码,如 JavaScript 的外部代码,否则它可能是浏览器自己的对象,例如全局窗口对象)。嵌入式 Flash 插件肯定会实现这个“接口”(因此浏览器将其视为另一个 NPObject)。
When you call a method on that object, there are several function that wrap that call serializing the data passed to the object and back to browser's runtime. It is difficult to tell for certain what exactly didn't work, but some common reasons would include:
当您对该对象调用方法时,有几个函数会包装该调用,将传递给对象的数据序列化并返回到浏览器的运行时。很难确定到底是什么不起作用,但一些常见的原因包括:
- The plugin does not expose (or did not register yet) a method with the name you are trying to call.
- The plugin was embedded in a way that crosscripting is not allowed (the limitations may be on both sides, Flash requires that the call comes from a trusted domain and you may restrict the plugin from communicating with environment through the settings in the object tag.
- An error thrown in the plugin's code invoked through JavaScript - I'm not sure that would be the same error, but it is very much likely.
- 该插件未公开(或尚未注册)具有您尝试调用的名称的方法。
- 插件的嵌入方式不允许跨脚本(限制可能是双方的,Flash 要求调用来自受信任的域,您可以通过对象标签中的设置限制插件与环境通信。
- 通过 JavaScript 调用的插件代码中抛出的错误 - 我不确定这是否会是相同的错误,但很有可能。
回答by stephanlindauer
I was getting the same error message. The problem only occurred when Flash made an ExternalInterface call that returned after Flash crashed (for what reason whatsoever). The fix I implemented was: Check if the Flash object is still up and running and if the callback is still a function of that object.
我收到了同样的错误信息。该问题仅在 Flash 进行了在 Flash 崩溃后返回的 ExternalInterface 调用时发生(无论出于何种原因)。我实施的修复是:检查 Flash 对象是否仍在运行,以及回调是否仍然是该对象的函数。