Flash与Flash之间如何通信JavaScript
我需要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题 - 这是 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.