關於 XML(一)使用 Flash 載入 XML 資料

var verLoader:URLLoader = new URLLoader(new URLRequest("version.xml"));
verLoader.addEventListener(Event.COMPLETE,OnComplete);
function OnComplete()
{
	var verXML:XML = new XML(verLoader.data);
	trace(verXML);
}

var articleXML:XML = new XML(articleLoader.data);
var i:Number=0;

while(articleXML.article[i])
{
	articles[i]=new Object();
	articles[i].aid=articleXML.article[i].aid;
	articles[i].photo=articleXML.article[i].photo;
	articles[i].title=articleXML.article[i].title;
	articles[i].description=articleXML.article[i].description;
	i++;
}

自定義附帶傳送參數事件

建構事件

package
{
	import flash.events.Event;
	public class MuseumEvent extends Event
	{
		public static const CHANGE_ROOM:String = "CHANGE_ROOM";
		public var data:Object;
		public function MuseumEvent(_type:String, _bubble:Boolean = false , _object:Object = null)
		{
			super(_type, _bubble, false);
			data = _object;
		}
	}
}

使用事件

// 收
this.addEventListener(MuseumEvent.CHANGE_ROOM,OnChangeRoom);

// 發
dispatchEvent(new MuseumEvent(MuseumEvent.CHANGE_ROOM,true,{room:"LOBBY"}));

// 執行
function OnChangeRoom(evt:MuseumEvent){trace(evt.data.zoom);}