我正在尝试使用ExternalInterface从我的javascript执行AS3函数。似乎在 IE 中工作正常,但 Firefox 总是返回 javascript 错误方法未定义。
我已经在谷歌上搜索了很长时间并排除了以下可能性:
1) 有些人说您需要在对象标记内添加一个嵌入标记,因此添加了一个 - 不走运。
2) 很多人说在调用 javascript 之前需要确保 Flash 已加载。我的电话是在按下页面上的链接后调用的。我总是先使用 Flash 应用程序,然后才按最后的链接。
3)然后我想这可能是一个安全问题所以添加了以下内容:
try {
ExternalInterface.addCallback("test", testing);
trace("added callback");
}
catch (error:SecurityError) {
trace("Security Error:"+error.message);
}
catch (error:Error) {
trace("Error:"+error.message);
}
但它打印出“添加的回调”:(
还有人有什么想法我还可以尝试什么吗?我正在运行最新的 Firefox 和 FlashPlayer 10。
问候,
奥利
最佳答案
想通了。 IE 需要使用 object 标签,FF 需要使用 embed 标签。尚未在其他浏览器上进行测试,但希望嵌入标签也适用于它们。
帮助其他有同样问题的人。这是一个适合我的 HTML 页面:)
问候,
奥利
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
html, body { height:100%; background-color: #ffffff;}
body { margin:0; padding:0; overflow:hidden; }
#flashContent { width:100%; height:100%; }
</style>
</head>
<script>
function testIt(){
var flashContainer;
if(navigator.appName.indexOf("Microsoft") != -1){
flashContainer = document.getElementById("test");
}else{
flashContainer = document.getElementById("test-embedded");
}
flashContainer.test("js says hello");
}
</script>
<body>
<a href="#" onclick="testIt();">Press here</a>
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="test" align="middle" width="550" height="400">
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src='test.swf' height='400' width='550' id='test-embedded' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>
</object>
</body>
</html>
关于actionscript-3 - AS3ExternalInterface适用于IE但不适用于Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4631322/