好久没有写AS3程序了。。。马丹连个xml读取都不会了快。。
下面是一个很好的例子,自己使用Flex biulder刚写的:
代码如下:
package { import flash.display.Sprite; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; public class TestXml extends Sprite { private var lod:URLLoader; private var url:String= "D:/testAS3/testX.xml"; private var urlRe:URLRequest; private var allXml:XML; public function TestXml() { this.init(); } private function init():void { urlRe = new URLRequest(url); lod = new URLLoader(); lod.load(urlRe); lod.addEventListener(Event.COMPLETE,this.completeHandler); } private function completeHandler(event:Event):void { var itemList:XMLList; var listLength:int =0; var item:XML; var index:int = 0; var str:String; allXml = new XML(lod.data); itemList = allXml.res; //trace(itemList); listLength = itemList.length(); while(index<listLength) { item = itemList[index]; str = ""; str = item.@url; trace(str+"\n"); index++; } } } }
下面是要加载的那个XML文件:
<li> <!-- 遊戲資源標識系列資訊 --> <!-- 如設參數isAbsoluteURL: 是否絕對路徑 主要是方便以後策劃更新數值後,設置不同路徑的調試 --> <res id="loadertext" url="xml/loadertext.xml" desc="显示文字" version="201501280001" /> <res id="localData" url="xml/localData/localData.9d" desc="数据包" version="201501280001" /> <res id="language" url="xml/language/language.9d" desc="语言包" version="201501280001" /> <res id="codeCode" url="error/codeData.9d" desc="错误语言包" version="201501280001" /> <res id="gmData" url="gm/gmData.9d" desc="指令语言包" version="201501280001" /> <res id="randomName" url="xml/randomName/randomName.9d" desc="随机名称语言包" version="201501280001" /> <res id="conductScript" url="xml/conductScript/conductScript.9d" desc="战斗行为资料包" version="201501280001" /> </li>
原文:http://www.cnblogs.com/duhuo/p/4385642.html