开发者

External Interface Problem: Error calling method on NPObject

开发者 https://www.devze.com 2023-04-07 19:28 出处:网络
Making a flash video streaming web-app using Actionscript 3\'s external Api.I am at a very rudimentary phase of the project where we\'re just experimenting with external interface.Right now i just hav

Making a flash video streaming web-app using Actionscript 3's external Api. I am at a very rudimentary phase of the project where we're just experimenting with external interface. Right now i just have a flash object and 3 buttons each to play pause and load a video. The only button that is currently set up to do anything is the load button. My swf and my html file sit on the same file system, and my video files sit on another server with traffic being redirected through a media server.

When i press the load button, which should just give it the path of the video file on it's server. Instead it throws an error that reads "Error: Error Calling method on NPObject".

Without further adieu, here are snippets of relevant code:

ACTIONSCRIPT:

function loadVideo(newVideo){
clearInterval(progressInterval);
videoFile = newVideo;
stream.play(videoFile, 0, 0);
videoPositions = "0,0";
};
ExternalInterface.addCallback( "loadVideo", loadVideo );

JAVSCRIPT: (in the head of my html document)

<head>
<title> External API Test</title>
<script type="text/javascript">
    var player = getFlashMovie();
    if (typeof MY == 'undefined')
    {
        MY = {};
    }

    MY.load = function()
    {
        console.log('load called');
        getFlashMovie().loadVideo("/media/preview/09/04/38833_2_720X405.mp4");
    };


    function getFlashMovie()
    {
        var isIE = navigator.appName.indexOf('Microsoft') != -1;
        return (isIE) ? window['MYVID'] : document['MYVID'];
    }
</script>
</head>

HTML:(in same document as javascript)

<body>
<div> This is a test</div>
<div class='my-media-player'>
    <object width="720" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id='MYVID'>
        <param value="as3VideoPlayer.swf" name="movie">
        <param value="high" name="quality">
        <param value="true" name="play">
        <param value="false" name="LOOP">
        <param value="transparent" name="wmode">
        <param value="always" name="allowScriptAccess">
        <embed width="720" height="405" name='MYVID' allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" loop="false" play="true" src="as3VideoPlayer.swf" wmode="transparent">
    </object>
    <div>
        <button type="button" class='play'>Play</button>
        <button type='button' class='pause'>Pause</button>
        <button type='button' class='load' onclick='MY.load()'>Load</button>
    </div>
</div>
</body>

Where is my mistake? I've read in a lot of places that this is an issue with security, but both my swf and html are in开发者_JAVA百科 the same folder on my local machine. Only the files come from outside, and in any case I think i've set the security settings correctly when i declare my flash player in the object tag, but maybe i'm missing something there.

if you can't solve my question directly can someone please explain what "error calling method on NPObject" means? I'm sure its specific to flash-js communications because i've never seen it before and that's what i have gathered from my googling.

Thank in advanced.


I highly suggest SWFObject. Aside from that, I dare say you need to allow script access:

<script type="text/javascript">
    // put your needed vars in the object below
    var flashVars = {};
    var params = {
         allowScriptAccess:"always"
    };

swfobject.embedSWF("myswf.swf", "myswf", "500", "400", "10.0.0", "", flashVars, params);

</script>


Can you try setting Security.allowDomain('*'); in your AS3 code right when it starts up?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号