未捕获的错误:在 NPObject 上调用方法时出错 [英] Uncaught Error: Error calling method on NPObject

查看:35
本文介绍了未捕获的错误:在 NPObject 上调用方法时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个 Flash 视频,如下所示:

<div id="myVideoContent"><h1>Oooppsss....你需要闪存或更新版本的闪存</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="获取 Adob​​e Flash 播放器"/></a></p>

以上内容附加到#VideoMain

然后我有以下内容:

$('#X.click').click(function(e) {var flash = document.getElementById("VideoMain");flash.sendToActionScriptPublishVideo(true);});

由于控制台错误而失败:

未捕获的错误:在 NPObject 上调用方法时出错.(匿名函数)jQuery.event.dispatchjquery.js:3256jQuery.event.add.elemData.handle.eventHandlejquery.js:2875

任何想法这里可能有什么问题?谢谢

解决方案

NPObject 是一个"interface"指向通过浏览器公开的任何外部"代码(外部代码,如 JavaScript 的外部代码,否则它可能是浏览器自己的对象,例如全局窗口对象).嵌入式 Flash 插件肯定会实现这个接口"(因此浏览器会将其视为另一个 NPObject).

当您对该对象调用方法时,有几个函数会包装该调用,将传递给对象的数据序列化并返回到浏览器的运行时.很难确定究竟是什么不起作用,但一些常见的原因包括:

  1. 插件未公开(或尚未注册)具有您尝试调用的名称的方法.
  2. 插件的嵌入方式不允许跨脚本(限制可能是双方的,Flash要求调用来自受信任的域,您可以通过对象中的设置限制插件与环境通信标签.
  3. 在通过 JavaScript 调用的插件代码中抛出的错误 - 我不确定这是否会是相同的错误,但很有可能.

I have a flash video on my page as follows:

<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

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

解决方案

NPObject is 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).

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:

  1. The plugin does not expose (or did not register yet) a method with the name you are trying to call.
  2. 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.
  3. 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.

这篇关于未捕获的错误:在 NPObject 上调用方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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