无法让Javascript与Flash交互

时间:2013-05-23 23:47:29

标签: javascript actionscript flash

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

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

Actionscript代码:

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>

1 个答案:

答案 0 :(得分:0)

好的,我想通了,我的库版本不支持allowDomain接受“*”作为参数。我用“localhost”替换它并且它有效。

相关问题