javascript - 通过Javascript触发ActionScript函数

标签 javascript actionscript

当点击浏览器关闭按钮时,我需要通过js调用actionscript 2函数。我怎样才能做到这一点?我尝试过,但没有成功。

AS2

import flash.external.*;
function test1() {
//do something
}

JS

<script type="text/javascript">      
        window.onbeforeunload = function(){
             test1();
             return 'text here' }; 
</script>

最佳答案

我可以在 ActionScript 3 中实现这一点。

JS代码:

window.onbeforeunload = function(){
            var flashObj = document.getElementById('fla');
                flashObj.changeText("closing");
             return 'text here'
              }; 

AS代码:

ExternalInterface.addCallback('changeText', changeText);
ss.text = "ello"
function changeText(val)
{
    ss.text = val;
}

这里 ss 是一个动态文本字段。

关于javascript - 通过Javascript触发ActionScript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23490813/

相关文章:

javascript - 从自动完成插件的 JSON 数组中获取额外参数

javascript - 在鼠标悬停时删除属性并在鼠标移开时添加回来

flash - 我尝试在Flash游戏中导入声音。它显示 “one or more files were not imported because there were problems reading them”。帮我

ActionScript 上的 Java Char

flash - 如何在全屏模式下启用键盘输入?

javascript - 显示和隐藏选项通常捕获到表中的单个 Id

javascript - 幻灯片背景图片

javascript - 区分 AJAX 上的多种表单

java - 压力测试 BlazeDS 的建议

python - 使用 JSON 序列化和反序列化对象