JavaScript获取执行flash中flash.external.ExternalInterface.addCallback注册的函数

  JavaScript如何获取并且执行flash中flash.external.ExternalInterface.addCallback注册的函数  

  测试浏览器:IE6,IE7,IE8,Firefox3.6,谷歌chrome 14.0.835.202 m

 

AS脚本

function loadPicture(){
//......代码......
//......代码......
}
flash.external.ExternalInterface.addCallback("forJS", null, loadPicture);//注册JavaScript中调用的回调函数

输出swf到html页面的JS脚本,swf的ID为swfId

document.write('<div class="dvswf">' 
+ (document.all ?
 '<object id=swfId classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><param name="src" value="/images/loadSwf.swf"></object>'
: '<embed id="swfId" type="application/x-shockwave-flash" src="/images/loadSwf.swf"/>') + '</div>');

测试代码如下

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312"/>
</head>
<body>
<script type="text/javascript">
    document.write('<div class="dvswf">' + (document.all ? '<object id=swfId classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><param name="src" value="/images/loadSwf.swf"></object>'
: '<embed id="swfId" type="application/x-shockwave-flash" src="/images/loadSwf.swf"/>') + '</div>');
</script>
<script type="text/javascript">
function $(Id){return document.getElementById(Id);}
function getFlashMethod(swfID) {//获取
    if (window[swfID] && window[swfID].forJS) alert('window')//IE,chrome
    if (document[swfID] && document[swfID].forJS) alert('document')//IE,Firefox
    if ($(swfID).forJS) alert('document.getElementById')//IE,Firefox,chrome
}
</script>
<input type="button" value="获取swf容器" onclick="getFlashMethod('swfId')" /><br />
</body>
</html>


  通过上面的测试代码可以知道IE,Firefox,谷歌chrome获取flash.external.ExternalInterface.addCallback注册的回调函数容器对象如下
IE:window,document,document.getElementById
Firefox:document,document.getElementById
谷歌chrome:window,document.getElementById
 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:JavaScript获取执行flash中flash.external.ExternalInterface.addCallback注册的函数

评论(1)Web开发网
阅读(400)喜欢(0)flash/flex/fcs/AIR