import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.events.MouseEvent;
var url:String="xml/config.xml";
var xml:XML;
var len:int;
var arr_title:Array=[];
var arr_url:Array=[];
var _oldNavi:Navi;
loadXML(url);
function loadXML(url:String):void {
var xmlLoader:URLLoader=new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded,false,0,true);
xmlLoader.load(new URLRequest(url));
}
function xmlLoaded(e:Event):void {
xml=XML(e.currentTarget.data);
len=xml.navi.length();
for (var i:int=0; i<len; i++) {
var _title:String=xml.navi[i].@title;
arr_title[i]=_title;
var _url:String=xml.navi[i].@url;
arr_url[i]=_url;
}
for (var j:int=0; j<len; j++) {
var navi:Navi=new Navi();
navi.name="navi"+j;
navi.tf_navi.text=arr_title[j];
bg.addChild(navi);
navi.x=250+j*navi.width;
navi.y=2;
navi.area.buttonMode=true;
if (j==len-1) {
navi._line.visible=false;
}
navi.area.addEventListener(MouseEvent.MOUSE_OVER,onNaviOver,false,0,true);
navi.area.addEventListener(MouseEvent.MOUSE_OUT,onNaviOut,false,0,true);
navi.area.addEventListener(MouseEvent.CLICK,onNaviClicked,false,0,true);
}
}
function onNaviOver(e:MouseEvent):void {
var _navi:Navi=e.currentTarget.parent as Navi;
//trace(_navi.clicked);
if (! _navi.clicked) {//因为clicked未指定类型,_navi.clicked此刻是undefined,此刻 if 判断 如果已经定义了,那么将颜色设置为白色
_navi.tf_navi.textColor=0xffff00;
}
}
function onNaviOut(e:MouseEvent):void {
var _navi:Navi=e.currentTarget.parent as Navi;
if (! _navi.clicked) {
_navi.tf_navi.textColor=0xfffffff;
}
}
function onNaviClicked(e:MouseEvent):void {
var _navi:Navi=e.currentTarget.parent as Navi;
if (_navi!=_oldNavi) {
if (_oldNavi) {
_oldNavi.tf_navi.textColor=0xfffffff;
}
_oldNavi=_navi;
_oldNavi.clicked=true;
_navi.tf_navi.textColor=0xff0000;
}
var index:int=int(_navi.name.slice(4));
//navigateToURL(new URLRequest(arr_url[index]),"_blank");
}