JS端 HTML
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="800" height="300" id="myFlash_ob" name="myFlash_ob" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="index.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="index.swf" quality="high" bgcolor="#ffffff" width="800" height="300" id="myFlash_em" name="myFlash_em" swLiveConnect="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<script>
var isready =false;
function isReady(){
return isready;
}
function getSWF(movieName)
{
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName+"_ob"];
} else {
return document[movieName+"_em"];
}
}
function toSetMenu(){
getSWF('myFlash').setmenu("http://www.baidu.com,http://www.google.cn,http://www.baidu.com,http://www.google.cn,http://www.baidu.com,http://www.google.cn");
}
window.onload = function(){
isready = true;
}
</script>
AS端
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.system.Security;
import flash.utils.Timer;
public class main extends Sprite
{
private var urls : Array;
private var req : URLRequest;
private var timer:Timer;
public function main()
{
Security.allowDomain("*");
Security.allowInsecureDomain("*");
timer = new Timer(200,1000);
timer.addEventListener(TimerEvent.TIMER,timehandler);
timer.start();
}
private function timehandler(evt:TimerEvent){
var isready:Boolean = ExternalInterface.call('isReady') as Boolean;
if(isready){
timer.removeEventListener(TimerEvent.TIMER,timehandler);
ExternalInterface.addCallback('setmenu',getlinks);
ExternalInterface.call('toSetMenu');
}
}
public function getlinks(links:String):void{
this.urls = links.split(',');
this.initEvents();
}
public function initEvents():void{
url_index.addEventListener(MouseEvent.CLICK,navigation_index);
url_yxzl.addEventListener(MouseEvent.CLICK,navigation_yxzl);
url_news.addEventListener(MouseEvent.CLICK,navigation_news);
url_grzx.addEventListener(MouseEvent.CLICK,navigation_grzx);
url_xgxz.addEventListener(MouseEvent.CLICK,navigation_xgxz);
url_wjjl.addEventListener(MouseEvent.CLICK,navigation_wjjl);
}
private function navigation_index(evt:MouseEvent):void{
this.req = new URLRequest(this.urls[0]);
navigateToURL(this.req,'_self');
}
private function navigation_yxzl(evt:MouseEvent):void{
this.req = new URLRequest(this.urls[1]);
navigateToURL(this.req,'_self');
}
private function navigation_news(evt:MouseEvent):void{
this.req = new URLRequest(this.urls[2]);
navigateToURL(this.req,'_self');
}
private function navigation_grzx(evt:MouseEvent):void{
this.req = new URLRequest(this.urls[3]);
navigateToURL(this.req,'_self');
}
private function navigation_xgxz(evt:MouseEvent):void{
this.req = new URLRequest(this.urls[4]);
navigateToURL(this.req,'_self');
}
private function navigation_wjjl(evt:MouseEvent):void{
this.req = new URLRequest(this.urls[5]);
navigateToURL(this.req,'_self');
}
}
}