[英]Basic Flash Question - call a javascript function at end of movie
I'm a .net developer who somehow has ended up trying to get some Flash working - this is completely new to me, so please be patient! 我是.net开发人员,以某种方式最终试图使Flash正常工作-这对我来说是全新的,所以请耐心等待!
I want to display a Flash video in a popup window, and when the video has finished playing, close the window using a javascript function "closeIt": 我想在弹出窗口中显示Flash视频,并在视频播放完毕后,使用javascript函数“ closeIt”关闭窗口:
<script>
function closeIt() {
alert("About to close...");
//code to close window here...
}
</script>
How can I achieve this? 我该如何实现? I have imported a video into Flash (choosing "load external video with playback component"). 我已将视频导入Flash(选择“使用播放组件加载外部视频”)。 This is in frame1. 这是在frame1中。 I thought that in the second frame I could make a call to ExternalInterface.call("closeIt") in the Actions window. 我以为在第二帧中,我可以在“动作”窗口中调用ExternalInterface.call(“ closeIt”)。 I have tried this, but when I publish and view the flash movie in a web brower, I never see the javascript alert. 我已经尝试过了,但是当我在网络浏览器中发布和查看Flash电影时,我再也没有看到javascript警报。
Can anyone help? 有人可以帮忙吗?
AS3, Option 1: AS3,选项1:
import flash.external.ExternalInterface;
(...)
ExternalInterface.call("closeIt()");
AS3, Option 2: AS3,选项2:
var request:URLRequest = new URLRequest("javascript:closeIt();");
navigateToURL(request, "_self");
You need the previously mentioned allowscript access for both methods, too: 对于这两种方法,您还需要前面提到的allowscript访问:
<param name="allowscriptaccess" value="always" />
You can call JavaScript functions from flash. 您可以从Flash调用JavaScript函数。
First you would update your OBJECT/EMBED script in the host HTML page to include: 首先,您将在主机HTML页面中更新OBJECT / EMBED脚本,以包括:
<param name="allowscriptaccess" value="always" />
Then from your code you can execute JavaScript method calls like: 然后,您可以从代码中执行JavaScript方法调用,例如:
getUrl('javascript:closeIt();');
Stick with AS3. 坚持使用AS3。 You want to use the ExternalInterface class. 您要使用ExternalInterface类。 Class Reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html 类参考: http : //help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html
Example Usage: 用法示例:
// import the package
import flash.external.ExternalInterface
// then launch that alert
ExternalInterface.call("closeIt");
Also I'd suggest you use firebug http://getfirebug.com to debug the JS part of it. 另外,我建议您使用firebug http://getfirebug.com调试它的JS部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.