Flash与Flash之间如何通信JavaScript

发布于 2024-08-10 03:49:39 字数 1910 浏览 6 评论 0原文

我需要使用 Javascript 调用 Flash 中的函数。为此,我使用ExternalInterface类(http://help.adobe.com/ru_RU/AS3LCR/Flash_10.0/flash/external/ExternalInterface.html)。但这对我不起作用。

SWF 在 HTML 页面中声明如下:

 <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="305" height="270" id="DemoPlayer" align="middle">
 <param name="allowScriptAccess" value="always" />
 <param name="allowFullScreen" value="false" />
 <param name="movie" value="DemoPlayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <embed src="DemoPlayer.swf" quality="high" bgcolor="#ffffff" width="305" height="270" name="DemoPlayer" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
 </object>

我尝试使用 Javascript 从 Flash 调用该函数:

function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }  
     function sendToActionScript(value) {
         thisMovie("DemoPlayer").sendToActionScript(value);
     }

在 Flash 中,我有:

ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);

在 FireFox 中,我收到此消息:“在 NPObject 上调用方法时出错![插件异常:Actionscript 中出现错误。使用try/catch 块来查找错误。]。”

我已经将参数“allowScriptAccess”的值更改为“always”,但这没有帮助。 也许这是ExternalInterface.addCallback(“sendToActionScript”,receivedFromJavaScript);的位置有问题。它位于“Adobe Flash”*.fla 文件的“Action-Frame”选项卡中。 (我是闪存新手)。

I need to call a function in Flash using Javascript. For this purpose I am using ExternalInterface class(example described in the end of http://help.adobe.com/ru_RU/AS3LCR/Flash_10.0/flash/external/ExternalInterface.html). But it does not work for me.

The SWF is declared in the HTML page like this:

 <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="305" height="270" id="DemoPlayer" align="middle">
 <param name="allowScriptAccess" value="always" />
 <param name="allowFullScreen" value="false" />
 <param name="movie" value="DemoPlayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <embed src="DemoPlayer.swf" quality="high" bgcolor="#ffffff" width="305" height="270" name="DemoPlayer" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
 </object>

I tried calling the function from Flash using Javascript:

function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }  
     function sendToActionScript(value) {
         thisMovie("DemoPlayer").sendToActionScript(value);
     }

In Flash I have:

ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);

In FireFox I get this message: "Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.]."

I've already changed the value of the param allowScriptAccess" to "always", but it doesn't help.
Maybe this is a problem with the location of ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript); it is located in the "Action-Frame" tab in the "Adobe Flash" *.fla file. (I'm new to flash).

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

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

发布评论

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

评论(1

云归处 2024-08-17 03:49:39

我发现了问题 - 这是 Flash Player 设置。首先,我只将我的 swf 文件添加为可信文件,但是当我添加整个目录时,它开始工作。

I found the problem - it was the Flash Player settings. First I added only my swf file as trusted, but when I added the whole directory it started working.

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