As3 load from XML


/ Published in: ActionScript 3
Save to your folder(s)

As3 load from XML----------------------


Copy this code and paste it in your HTML
  1. //�root.xml中读�status,a����������询xml
  2. public static function readStatus(a:String):ArrayCollection{
  3. var xml:XML;
  4. var xmlList:XMLList;
  5. var xmlLoader:URLLoader = new URLLoader();
  6.  
  7. var arr:ArrayCollection = new ArrayCollection();
  8. xmlLoader.load(new URLRequest("pb/utils/root.xml"));
  9.  
  10. xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
  11.  
  12. function xmlLoaded(event:Event):void
  13. {
  14. xml = XML(event.target.data);
  15. //��scope��
  16. xmlList = xml..userStatus.(@scope==a);
  17. //trace(xmlList[0].@label);
  18. for(var i:int = 0; i < xmlList.length(); i++)
  19. {
  20. //�xmlList转�为object类�
  21. var o:Object = new Object();
  22. o.label = xmlList[i].@label;
  23. o.data = xmlList[i].@data;
  24. arr.addItemAt(o,i);
  25.  
  26. }
  27. }
  28. return arr;
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.