外部接口问题:调用 NPObject 上的方法时出错

发布于 2024-12-06 15:10:53 字数 2673 浏览 1 评论 0原文

使用 Actionscript 3 的外部 Api 制作 Flash 视频流 Web 应用程序。我正处于项目的一个非常初级的阶段,我们只是尝试外部接口。现在我只有一个 Flash 对象和 3 个按钮,每个按钮用于播放暂停和加载视频。当前设置为执行任何操作的唯一按钮是加载按钮。我的 swf 和 html 文件位于同一文件系统上,我的视频文件位于另一台服务器上,流量通过媒体服务器重定向。

当我按下加载按钮时,它应该只给出视频文件在其服务器上的路径。相反,它会抛出一个错误,内容为“错误:在 NPObject 上调用方法时出错”。

无需进一步告别,这里是相关代码片段:

ACTIONSCRIPT:

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

JAVSCRIPT: (在我的 html 文档的头部)

<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:(与 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>

我的错误在哪里?我在很多地方都读到这是一个安全问题,但我的 swf 和 html 都位于本地计算机上的同一文件夹中。只有文件来自外部,无论如何,当我在对象标记中声明我的 Flash 播放器时,我认为我已经正确设置了安全设置,但也许我在那里丢失了一些东西。

如果您不能直接解决我的问题,有人可以解释一下“NPObject 上的错误调用方法”是什么意思吗?我确信它特定于 flash-js 通信,因为我以前从未见过它,这就是我从谷歌搜索中收集到的信息。

提前致谢。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪落纷纷 2024-12-13 15:10:54

我强烈建议使用 SWFObject。除此之外,我敢说您需要允许脚本访问:

<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>

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>
小鸟爱天空丶 2024-12-13 15:10:54

您可以尝试设置 Security.allowDomain('*');在你的 AS3 代码启动时就在它里面?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文