Friday, November 16, 2007

Load xml ลงใน Flash AS3

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, onLoadXML); //โหลดเรียบร้อยไปใช้ฟังก์ชั่น onLoadXML
loader.load(new URLRequest("XML/testmy.xml"));


function onLoadXML(ev:Event) {
try { var myXML:XML = new XML(ev.target.data);
for (var i=0; i trace(myXML.dramalist[i].title);
trace(myXML.dramalist[i].time);
}
} catch (e:TypeError) {
trace("Could not parse the XML");
trace(e.message);
}
}

No comments: