【问题标题】:Can't get Javascript to interact with Flash无法让 Javascript 与 Flash 交互
【发布时间】:2013-05-19 12:12:19
【问题描述】:

我无法让我的 Javascript 影响我的 SWF 对象。 该对象在浏览器中正确呈现,但我无法调用暴露给 ExternalInterface 的“填充”方法。 未调用就绪函数“flashReady”。从控制台直接调用它表示flash对象没有“填充”功能。等待一段时间然后调用该函数没有帮助。

错误是TypeError:Object HTMLObjectElement has no method 'fill'

动作脚本代码:

public class Main extends Sprite
{

  public function Main() {
     graphics.beginFill(0xff0000);
     graphics.drawRect(0, 0, 200, 100);
     graphics.endFill();
     Security.allowDomain("*");
     ExternalInterface.addCallback("fill", fill);
     ExternalInterface.call("flashReady");
  }

  public function fill():void {
      graphics.beginFill(0x00ff00);
      graphics.drawRect(0, 0, 200, 100);
      graphics.endFill();
  }

}

HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <title>
        Flash UI Demo
    </title>
    <script type="text/javascript" src="swfobject.js">
    </script>
    <script type="text/javascript">
        function flashReady() {
            document.getElementById('AddCallbackExample').fill();
        }
        var swfVersionStr = "0";
        var xiSwfUrlStr = "";
        var flashvars = {};
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "always";
        var attributes = {};
        attributes.id = "AddCallbackExample";
        attributes.name = "AddCallbackExample";
        attributes.align = "middle";
        swfobject.embedSWF(
            "http://localhost:8001/swf", "flash",
            "100%", "100%",
            swfVersionStr, xiSwfUrlStr,
            flashvars, params, attributes);
    </script>
</head>
<body>
    <div id="flash" />
</body>
</html>

【问题讨论】:

  • 我删除了 Flex 标签;因为这与 Flex 框架无关。
  • 尝试将 ExternalInterface.call("console.log", "test"); 放入您的 Flash 以查看错误发生的确切位置,以及它是否是 ActionScript 或 JavaScript 中的错误。

标签: javascript actionscript flash


【解决方案1】:

好的,我想通了,我的库版本不支持 allowDomain 将“*”作为参数。我用“localhost”替换了它,它起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 2010-09-09
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多