Uncaught Error: Error calling method on NPObject
Asked Answered
T

2

35

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

Thacker answered 20/1, 2012 at 4:38 Comment(0)
S
74

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.
Suannesuarez answered 20/1, 2012 at 9:4 Comment(5)
The third one was what was going wrong for me - if you're using Flash, then there's an error being thrown in the function called by JS - using try..catch blocks can either contain it, or help you narrow down where the problem is so you can fix itParticularism
I got this error when JS was trying to call exposed Flash method but proper System.security.allowDomain() / System.security.allowinsecureDomain() was not called. If you call allowDomain() then make sure your HTML is loaded over same protocol as the SWF (HTTPS or HTTP).Doorman
4) the method you add as a callback must be scoped to : public 5) passing an undefined value to this method can create this message (if you expect a String in flash)Historicity
for me, Secrity.allowDomain("domain.com") solved the problem, where domain.com is the website domain that hosts the javascript calling my swfSelfopinionated
(4) solution from YopSolo worked for me. And this is strange: Many times I did this, and always private methods worked fine, but this time public is required.Phenomenology
M
1

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.

Moppet answered 24/10, 2013 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.