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

19,959

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
19,959
Kirkman14
Author by

Kirkman14

Check out my two blogs: Break Into Chat - Retrocomputing interviews, essays and reminiscences. Particular focus on BBS door games and Atari computer The Extraordinary Renaud Family - stories, photos, and videos of my clan

Updated on June 20, 2022

Comments

  • Kirkman14
    Kirkman14 almost 2 years

    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.com and the SWFs are on images.somedomain.com. 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.com/q1tattooquiz.swf" type="application/x-shockwave-flash" width="600" height="350">
            <param name="movie" value="http://images.somedomain.com/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?