【问题标题】:Call javascript function from flash button Flash CS5从 Flash 按钮 Flash CS5 调用 javascript 函数
【发布时间】:2011-02-15 18:54:50
【问题描述】:

当有人点击与某个 div 相关的 flash 按钮时,我试图显示一个 div。这是我试图调用的 javascript 函数:

<script type="text/javascript">
    function show1() {
        document.getElementById(#table1).style.display = 'block';
    }
</script>

"#table1" 是我在用户单击 Flash 中的按钮后尝试显示的 Div ID。我没有永远使用闪存,并且正在努力寻找答案;它曾经是你可以通过 getURL 路由来调用它,但这不再起作用了。有谁知道我会如何调用该函数来显示 div?

提前致谢。

【问题讨论】:

标签: javascript flash actionscript-3 function flash-cs5


【解决方案1】:

您想使用外部接口。在 flash 里面只写 ExternalInterface.call("show1");

【讨论】:

    【解决方案2】:

    使用 ExternalInterface 更新 AS 3.0:

    由于某种原因,标记为 &lt;script type="text/javascript"&gt;&lt;/script&gt; 时 JavaScript 无法工作。所以,改变你的 html 部分。

    HTML:

    <script language='javascript'>
    function show1(){
          document.getElementById('table1').style.display = 'block';
    }
    </script>
    

    Actionscript 3.0:

    import flash.external.ExternalInterface;
    button_1.addEventListener(MouseEvent.CLICK, function(){ 
         ExternalInterface.call("show1", "param");
    });
    

    确保在 html 中的 'allowScriptAccess' 在 AC_FL_RUnContent、对象参数和嵌入中设置为 'always'。

    【讨论】:

    • 我可以这样做,但是当我发布电影时,它会调试并完全搞砸 getURL 函数中的所有内容。有没有办法在电影本身中允许它?
    • 你正在使用哪个版本的 actionscript,当你说 getURL func 搞砸了,你是什么意思?
    • 这是我尝试过的代码... button_17.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);函数 fl_MouseClickHandler_2(event:MouseEvent):void { getURL("javascript:show1();"); }
    • 我也尝试了外部接口代码,但我也无法让它工作。我完全不知所措。
    猜你喜欢
    • 1970-01-01
    • 2011-05-17
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多