访问 Google Chrome 中的 ExternalInterface 公开方法时出现问题 [英] Problem accessing ExternalInterface exposed method in Google Chrome

查看:31
本文介绍了访问 Google Chrome 中的 ExternalInterface 公开方法时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的简单动作脚本我正在尝试使用 Flash 的 ExternalInterface 来设置一个回调,以便 JavaScript 可以调用我的 Flash 对象上的方法.在 Safari、Firefox 和 IE 中一切正常,但我无法让 Chrome 工作.当我在 Chrome 上尝试代码时,出现以下错误:

<块引用>

未捕获的类型错误:对象#没有方法'设置文本'

这是我正在使用的 HTML 示例(同样,在 Safari、FF 和 IE 中也能正常工作)

<div id="我的内容"></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'});函数 getFlash(电影名称){返回 ( navigator.appName.indexOf("Microsoft") != -1) ?窗口[电影名] : document.getElementById(电影名);}</script><p><input type="text" id="exampleText"/><input type="button" value="Set Text" onclick="getFlash('hw').setText(document.getElementById('exampleText').value)"/>

这里是 ActionScript...

包{导入 flash.display.Sprite;导入 flash.text.TextField;导入 flash.external.ExternalInterface;导入 flash.system.Security;公共类 HelloWorld 扩展 Sprite {私有 var textField:TextField = new TextField();公共函数 HelloWorld() {Security.allowDomain("*");ExternalInterface.addCallback("setText", this.setText);textField.text = "你好,世界!";addChild(textField);}公共函数 setText(text:String):void {this.textField.text = 文本;}}}

解决方案

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

解决方案是使用来自 Adob​​e 的 AC_OETags.js 文件作为嵌入脚本而不是 JQuery flash.(在Client Side detection下的zip文件中可以找到,Adobe可能在其他地方也有)

Flash 在浏览器中构建 javascript 回调时基于竞争条件的问题.由于某种原因,这不能通过直线嵌入正确处理.

<脚本>//需要 Flash 的主要版本var requiredMajorVersion = 10;//需要小版本的 Flashvar requiredMinorVersion = 0;var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);AC_FL_RunContent("src", "tagflash",宽度",200",高度",200","id", "myTagFlash",质量",高","bgcolor", "#FFFFFF","name", "myTagFlash","allowScriptAccess","总是",类型",应用程序/x-shockwave-flash","插件页面", "http://www.adobe.com/go/getflashplayer","flashvars", "templateData=theYear:2010&theTagNumber:123");

然后你可以这样做:(适用于 IE、FF、Safari、Crome、++)

$("#tagFlash").gotoNewFrame();

My simple ActionScript I am trying to use Flash's ExternalInterface to setup a callback so that JavaScript can call a method on my Flash object. Everything works fine in Safari, Firefox and in IE, but I cannot get Chrome working. When I try the code on Chrome, I get the following error:

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

Here is the example HTML I am using (again, works fine in Safari, FF and 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>

and here is the 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;
    }   
  }
}

解决方案

I got the same problem, to fire and recieve listener events between javascript and flash.

The solution was to use AC_OETags.js file from Adobe as embedd script instead of JQuery flash. (It is found in the zip file under Client Side detection, Adobe probably have it some other places as well)

The trouble based on a race condition when the flash builds the javascript callbacks in the browser. This is not handeled correctly by a straight embed for some reason.

<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", "200",
    "id", "myTagFlash",
    "quality", "high",
    "bgcolor", "#FFFFFF",
    "name", "myTagFlash",
    "allowScriptAccess","always",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer",
    "flashvars", "templateData=theYear:2010&theTagNumber:123"
);
</script>
</div>

Then you can do: (works in IE, FF, Safari, Crome,++)

$("#tagFlash").gotoNewFrame();

这篇关于访问 Google Chrome 中的 ExternalInterface 公开方法时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆