1 Reply Latest reply on Mar 22, 2010 8:19 PM by new2oop

    extracting array from loaded xml


      I'm using Flex 4 in an AIR project and need to load the following xml text file





          <month name="Jan-04" revenue="400263" average="80052">

              <region name="APAC" revenue="46130"/>

              <region name="Europe" revenue="106976"/>

              <region name="Japan" revenue="79554"/>

              <region name="Latin America" revenue="39252"/>

              <region name="North America" revenue="128351"/>



          <month name="Feb-04" revenue="379145" average="75829">

              <region name="APAC" revenue="70324"/>

              <region name="Europe" revenue="88912"/>

              <region name="Japan" revenue="69677"/>

              <region name="Latin America" revenue="59428"/>

              <region name="North America" revenue="90804"/>




      The original example (the old Flex 2 Dashboard example) used

         <mx:HTTPService id="srv" url="results.xml" useProxy="false" result="resultHandler(event)"/>


      to load the xml file, then used the line:

                  monthData = event.result.list.month.source as Array;


      to convert the text to an array. Since this is an AIR project I'm using Filestream etc. to load the file but cannot convert it to an array. Not sure why. Here is the filestream code:


      private function loadFile():void{

      var file:File = File.applicationDirectory.resolvePath("results.xml");

      var fileStream:FileStream = new FileStream();

      fileStream.open(file, FileMode.READ);

      var xmlList:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));


      monthData = xmlList.month.source as Array;





      but the trace is always null no matter what I try.

        • 1. Re: extracting array from loaded xml
          new2oop Level 1

          Ignore all the httpService vs Filestream, the xml seems to be loading ok but I can't extract the array from the xml. The original example was from Flex 2 so I'm not sure if something has changed but the original


          monthData = xmlXML.month as Array;


          doesn't work. The xml seems fine as I can extract anything from it.



          I just can't turn it into an Array like in the original.