gpt4 book ai didi

javascript - 通过 Actionscript 调用 JS

转载 作者:行者123 更新时间:2023-11-30 17:52:10 25 4
gpt4 key购买 nike

我正在尝试使用 ActionScript3 运行 Javascript。

这是绑定(bind)到按钮的代码:

import flash.external.ExternalInterface;

function call_javascript(evt:MouseEvent):void {
ExternalInterface.call("alert", "JS");
}

js_btn.addEventListener(MouseEvent.MOUSE_UP, call_javascript);

这是我的 HTML:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="js" align="middle">
<param name="movie" value="js.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name='AllowScriptAccess' value='always'/>
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="js.swf" width="550" height="400">
<param name="movie" value="js.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="always" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Scarica Adobe Flash Player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>

当我按下按钮时没有任何反应,为什么?我正在使用 FlashProfessional CS6

最佳答案

call() method将 js 函数名称和参数作为单独的参数。

试试这个:

ExternalInterface.call("alert", "JS");

编辑:您还需要 allow script access在您的 HTML 页面中。

将此添加到您的 SWF 容器 HTML 页面

<param name='AllowScriptAccess' value='always'/>

例如:

<object id='MyMovie.swf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' height='100%' width='100%'> 
<param name='AllowScriptAccess' value='always'/>
<param name='src' value=''MyMovie.swf'/>
<embed name='MyMovie.swf' pluginspage='http://www.adobe.com/go/getflashplayer' src='MyMovie.swf' height='100%' width='100%' AllowScriptAccess='never'/>
</object>

编辑 2: 仅当文件属于本地信任的安全沙箱时,在本地运行此程序才有效。来自文档:

For SWF files running locally, calls to these methods are successful only if the SWF file and the containing web page (if there is one) are in the local-trusted security sandbox. Calls to these methods fail if the content is in the local-with-networking or local-with-filesystem sandbox.

关于javascript - 通过 Actionscript 调用 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18768087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com