最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I overcome "Error calling method on NPObject" and Play() a SWF? - Stack Overflow

programmeradmin2浏览0评论

I am working on a quiz system. Normally it uses jpeg images with each question. But a few of the quizzes instead feature animated .SWF files. I want to use jquery swfobject to call the play() method, once the user has clicked on an answer.

My solution works fine locally, but when I try to run it online, it throws the "Error calling method on NPObject!" message.

The quiz HTML is located on www.somedomain and the SWFs are on images.somedomain. So, I'm guessing this is a cross-domain thing.

Trouble for me is, I don't know anything about Flash... how to edit SWF files, anything about Flash attributes, or the like.

Here's an example of my code:

<div class="photos">
    <object data=".swf" type="application/x-shockwave-flash" width="600" height="350">
        <param name="movie" value=".swf">
        <param name="wmode" value="opaque">
    </object>
</div>

And the javascript:

if (hasFlash) {
    $('#question'+quesNum+' .photos').flash(function() { this.Play(); } );
    }

It's pretty simple, and as I said, it works fine on my PC. But once uploaded, it errors out.

What can I add to my javascript to make these files work right?

I am working on a quiz system. Normally it uses jpeg images with each question. But a few of the quizzes instead feature animated .SWF files. I want to use jquery swfobject to call the play() method, once the user has clicked on an answer.

My solution works fine locally, but when I try to run it online, it throws the "Error calling method on NPObject!" message.

The quiz HTML is located on www.somedomain. and the SWFs are on images.somedomain.. So, I'm guessing this is a cross-domain thing.

Trouble for me is, I don't know anything about Flash... how to edit SWF files, anything about Flash attributes, or the like.

Here's an example of my code:

<div class="photos">
    <object data="http://images.somedomain./q1tattooquiz.swf" type="application/x-shockwave-flash" width="600" height="350">
        <param name="movie" value="http://images.somedomain./q1tattooquiz.swf">
        <param name="wmode" value="opaque">
    </object>
</div>

And the javascript:

if (hasFlash) {
    $('#question'+quesNum+' .photos').flash(function() { this.Play(); } );
    }

It's pretty simple, and as I said, it works fine on my PC. But once uploaded, it errors out.

What can I add to my javascript to make these files work right?

Share edited Apr 9, 2011 at 21:24 Kirkman14 asked Apr 9, 2011 at 20:33 Kirkman14Kirkman14 1,6864 gold badges17 silver badges31 bronze badges 2
  • For what it's worth, I installed FlashBug to see if it might be of some help, but I'm not getting any warnings or errors there. Only the "Error calling method on NPObject” error on the normal console. – Kirkman14 Commented Apr 9, 2011 at 22:58
  • Okay, I think I have pretty much determined this is a crossdomain issue. When the SWFs are on the same domain as the HTML, all is well. So the question remains: Short of redoing the SWFs to add security code (which I can't do), is there any other solution to get them to play? – Kirkman14 Commented Apr 11, 2011 at 0:27
Add a ment  | 

5 Answers 5

Reset to default 4

Kirkman14,

Apart from the allowScriptAccess thingy, make sure you are calling the functions with the correct number of parameters, matching AS declaration. If your AS declares:

function playSound(event:MouseEvent):void{
// code here
}

then make sure you use the function accordingly playSound(null). I've been through this myself.

I think there isn't a way to avoid changing the SWF. You need to put this line in Flash: flash.System.Security.allowDomain('*'); This is only needed it you are trying to call a function in the SWF from JS. For the opposite direction, also set allowScriptAccess to always in your embed code. Note that this param might be case-sensitive, if I remember correctly.

You could try setting allowscriptaccess to "always". allowscriptaccess is the same kind of parameter as wmode in your sample code.

It was suggested to me to create crossdomain.xml files that whitelist domains the flash will municate with. I haven't had any success with this yet though (but perhaps my problem is different from yours).

For me, this issue arose because, in Flex, I'd set to static a function that bore ExternalInterface calls. If the problem function is static, try undoing that.

发布评论

评论列表(0)

  1. 暂无评论