javascript – 在Google Chrome中访问ExternalInterface公开方法时遇到问题

前端之家收集整理的这篇文章主要介绍了javascript – 在Google Chrome中访问ExternalInterface公开方法时遇到问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我简单的ActionScript
我正在尝试使用Flash的 ExternalInterface来设置回调,以便JavaScript可以在我的Flash对象上调用方法.在Safari,Firefox和IE中一切正常,但我无法让Chrome正常工作.当我在Chrome上试用代码时,出现以下错误

Uncaught TypeError: Object #<an
HTMLObjectElement> has no method
‘setText’

这是我正在使用的示例HTML(再次,在Safari,FF和IE中正常工作)

<html><body>
<div id="mycontent"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("http://invincible.dynalias.com:8080/HelloWorld.swf","mycontent","400","420","9.0.0","expressInstall.swf",{},{allowScriptAccess:'always'},{id:'hw',name:'hw'});

function getFlash(movieName) {
   return ( navigator.appName.indexOf("Microsoft") != -1) ? window[movieName] : document.getElementById(movieName);
}
</script><p>
  <input type="text" id="exampleText" /> <input type="button" value="Set Text" onclick="getFlash('hw').setText(document.getElementById('exampleText')
.value)" />
</body>
</html>

这是ActionScript ……

package {
  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.external.ExternalInterface;
  import flash.system.Security;

  public class HelloWorld extends Sprite {

    private var textField:TextField = new TextField();
    public function HelloWorld() {
      Security.allowDomain("*");
      ExternalInterface.addCallback("setText",this.setText);
      textField.text = "Hello,world!";
      addChild(textField);
    }   
    public function setText(text:String):void {
      this.textField.text = text;
    }   
  }
}

解决方法

我遇到了同样的问题,在javascript和flash之间触发和接收监听器事件.

解决方案是使用Adobe的AC_OETags.js文件作为嵌入脚本而不是JQuery flash. (它可以在客户端检测下的zip文件中找到,Adobe可能还有其他一些地方)

当flash在浏览器中构建javascript回调时,基于竞争条件的麻烦.出于某种原因,直接嵌入不能正确处理这个问题.

<div>
<script>
// Major version of Flash required
var requiredMajorVersion = 10;
// Minor version of Flash required
var requiredMinorVersion = 0;

var hasRequestedVersion = DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);
AC_FL_RunContent(
"src","tagflash","width","200","height","id","myTagFlash","quality","high","bgcolor","#FFFFFF","name","allowScriptAccess","always","type","application/x-shockwave-flash","pluginspage","http://www.adobe.com/go/getflashplayer","flashvars","templateData=theYear:2010&theTagNumber:123"
);
</script>
</div>

然后你可以这样做:(在IE,FF,Safari,Crome中工作)

$("#tagFlash").gotoNewFrame();
原文链接:https://www.f2er.com/js/156031.html

猜你在找的JavaScript相关文章