Connect with Expertise | Find Experts, Get Answers, Share Insights

AS3.0 - How do I store an XML table into a Flash Array?

 
Join Date: Jan 2010
Posts: 3
#1: Jan 19 '10
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <posts>
  3. <item>2</item>
  4. <item>3</item>
  5. </posts>
  6.  
What do I need to type in Actionscript so that I can put this information into an Array?

I need to be able to trace out the individual elements in separate textboxes in Flash. As far as my knowledge goes, I only thought of this method of doing it.

Is there any better method as to how I can go about doing this?

Hope to get some responses soon. (:

 
Join Date: Jan 2010
Posts: 18
#2: Jan 20 '10

re: AS3.0 - How do I store an XML table into a Flash Array?


Heres the code, assuming the file is called file.xml and you want to load it from a file.
Expand|Select|Wrap|Line Numbers
  1. var loader:URLLoader = new URLLoader();
  2. loader.addEventListener(Event.COMPLETE, loadXML);
  3. loader.load(new URLRequest("file.xml"));
  4. var xml;
  5. function loadXML(e:Event):void
  6. {
  7.         xml = new XML(e.target.data);
  8.         trace(xml); // Outputs the whole file
  9.         for (var i in xml.item)
  10.         {
  11.             trace(xml.item[i]);
  12.         }
  13. }
  14.  
Reply