1、
判断各种浏览器
JS 获取swf对象的写法:
thisMapMovie("donghua").startPlay();
//Flash 注册完回调函数之后后调用 function isReady() { isReady = 1; alert(" 抽奖Flash 动画准备完毕"); } //按钮响应 开始播放调用Flash函数 function startPlay(){ if(isReady == 1){ alert(" startPlay "); thisMapMovie("donghua").startPlay(); }else{ alert(" Flash 还未准备完。"); } }
function thisMapMovie(movieName) { if (window.document[movieName]) { return window.document[movieName]; } if (navigator.appName.indexOf("Microsoft Internet") == -1) { if (document.embeds && document.embeds[movieName]){ return document.embeds[movieName]; } else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) { //return document.getElementByIdx_x_x(movieName); return document.getElementById(movieName); } } }
2、加载swf文件的写法
Google Chrome浏览器的写法注意要加上
<embed
要加上参数 play="false" allowScriptAccess="always" ;否则会自动播放 并且不响应swf文件里面的as代码的操作。
加载swf 文件的写法
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="donghua" align="middle"> <param name="movie" value="donghua.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="window" /> <param name="scale" value="showall" /> <param name="menu" value="true" /> <param name="devicefont" value="false"/> <param name="salign" value="" /> <param name="allowScriptAccess" value="always" /> <param name="swliveconnect" value="true"/> <embed play="false" allowScriptAccess="always" swliveconnect="true" name="donghua" src="donghua.swf" quality="high" bgcolor="#FFFFFF" width="550" height="400" type="application/x-shockwave-flash" swliveconnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"/> </object>
3、 AS的代码
public function docMain() { Security.allowDomain("*"); Security.allowInsecureDomain("*"); init(); } private function init():void{ //注册as函数,外部js调取 if (ExternalInterface.available) { ExternalInterface.addCallback("startPlay", startFlash); ExternalInterface.call("isReady"); } this.stop(); }