在Chrome浏览器中访问ExternalInterface公开方法的问题 [英] Problem accessing ExternalInterface exposed method in Google Chrome

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

问题描述

我简单的ActionScript
我想用Flash的> ExternalInterface 来设置回调,以便JavaScript可以调用我的Flash对象上的方法。一切工作正常在Safari浏览器,Firefox和IE中,但我不能让Chrome工作。当我在Chrome上尝试代码时,出现以下错误:


Uncaught TypeError:Object#< an
HTMLObjectElement>没有方法
'setText'

下面是我使用的HTML示例(同样,在Safari中工作正常,FF和IE)

 < html>< body> 
< div id =mycontent>< / div>
< script type =text / javascriptsrc =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(movieName){
return(navigator.appName.indexOf(Microsoft)!= -1)? window [movieName]:document.getElementById(movieName);
}
< / script>< p>
< input type =textid =exampleText/> < input type =buttonvalue =Set Textonclick =getFlash('hw')。setText(document.getElementById('exampleText')
.value)/>
< / body>
< / html>

这里是ActionScript ...

  package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.external.ExternalInterface;
导入flash.system.Security;
$ b $ public class HelloWorld extends Sprite {
$ b $ 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;




$ div class =h2_lin>解决方案解决方法是使用 www.adobe.com/products/flashplayer/download/detection_kit/rel =nofollow> AC_OETags.js 文件作为嵌入脚本而不是JQuery Flash。 (它可以在客户端检测下的zip文件中找到,Adobe可能也有其他一些地方)

当闪存建立在浏览器中的JavaScript回调。

 < div>这不是直接嵌入的正确方式。 
< script>
//需要Flash的主要版本
var requiredMajorVersion = 10;
//需要一些小版本的Flash
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,总是,
type,application / x-shockwave-flash,
pluginspage,http://www.adobe.com/go/getflashplayer,
flashvars,templateData = theYear:2010& theTagNumber:123
);
< / script>
< / div>

然后你可以这样做:(在IE,FF,Safari,Crome, p>

  $(#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();

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

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