import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; var xml:XML; var ldr:URLLoader = new URLLoader(new URLRequest("D:/SCMIS - 天津非春节版/Program/Config/menu.xml")); ldr.addEventListener(Event.COMPLETE,onLoaded); function onLoaded(e:Event):void { xml = XML(e.target.data); trace(search(xml,"btnCharm")); } function searchXMLByName(name:String,args:String=""):XML { return search(xml,name); } function search(xml:XML,name:String):XML { var len:int = xml.menu.length(); for (var i:int = 0; i<len; i++) { if (xml.menu[i].@name == name) { return XML(xml.menu[i]); } } for (i= 0; i<len; i++) { if (xml.menu[i].menu.length() > 1) { var newXML:XML = search(XML(xml.menu[i]),name); if (newXML==null) { continue; } else { return newXML; } } } return null; }