AS3加载Xml文件的代码
import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; import flash.display.Loader; private var myXML:XML; // pass the path to the xml, and the function to execute once it's loaded private function loadXML (path:String, nextFunc:Function):void { var loader:URLLoader = new URLLoader (); var req:URLRequest = new URLRequest (path); loader.addEventListener (ProgressEvent.PROGRESS, progressHandler, false, 0, true); loader.addEventListener (Event.COMPLETE, nextFunc, false, 0, true); loader.load (req); } private function progressHandler (evt:Event):void { var percent:Number = evt.currentTarget.bytesLoaded / evt.currentTarget.bytesTotal; trace (percent); } // the COMPLETE function that executes when the file is laoded private function myXMLLoaded (evt:Event):void { myXML = new XML(evt.target.data); // myXML.item[0] } // call the file to load and the COMPLETE function for when its done loadXML ("myFile.xml", myXMLLoaded);