as3读取xml文件
root.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <root>
- <Sysm>
- <userStatus label="0" data="正常" scope="user"/>
- <userStatus label="1" data="过期" scope="user"/>
- <userStatus label="2" data="删除" scope="user"/>
- <userStatus label="3" data="禁用" scope="user"/>
- </Sysm>
- </root>
as3:
- //从root.xml中读取status,a是参数,用来选择性查询xml
- public static function readStatus(a:String):ArrayCollection{
- var xml:XML;
- var xmlList:XMLList;
- var xmlLoader:URLLoader = new URLLoader();
- var arr:ArrayCollection = new ArrayCollection();
- xmlLoader.load(new URLRequest("pb/utils/root.xml"));
- xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
- function xmlLoaded(event:Event):void
- {
- xml = XML(event.target.data);
- //选择scope属性
- xmlList = xml..userStatus.(@scope==a);
- //trace(xmlList[0].@label);
- for(var i:int = 0; i < xmlList.length(); i++)
- {
- //把xmlList转化为object类型
- var o:Object = new Object();
- o.label = xmlList[i].@label;
- o.data = xmlList[i].@data;
- arr.addItemAt(o,i);
- }
- }
- return arr;
- }