1 Reply Latest reply on Feb 9, 2010 7:15 AM by Gregory Lafrance

    accessing xml nodes through actionscript

    Sen Imagines

      Hi,

       

      I am using an external XML data for a chart.

      I am loading using a httpService.

       

      I wish to manipulate the xml data before creating a data provider for a dynamic series for the chart

      How can I access the xml nodes through actionscript ?

       

      Sample XML: MyChartData

       

      <?xml version="1.0" encoding="utf-8"?>

      <data>

           <result month="Jan">test1</result>

           <result month="Feb">test2</result>

      </data>

       

      MXML:

       

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="srv.send();">
      <mx:HTTPService id="srv" url="MyChartData.xml"/>


      <mx:Script>
      <![CDATA[
         public function GenerateMySeries():void
         {
          var myseries:ColumnSeries = new ColumnSeries();
          myseries.dataProvider = srv.lastResult.data.result;
          myseries.yField = "Result";
          myChart.series.push(myseries);
         }
      ]]>
      </mx:Script> 


      <mx:Button label="Create Series" click="GenerateMySeries()"/>
      <mx:ColumnChart id="myChart" .....

      .....
      </mx:ColumnChart>

       

       

       

       

       

        • 1. Re: accessing xml nodes through actionscript
          Gregory Lafrance Level 6

          Instead of using lastResult to access the data, use a result handler method as below:

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="srv.send();">
          <mx:HTTPService id="srv" url="MyChartData.xml" resultFormat="e4x" result="dataFunc(event)"/>


          <mx:Script>
          <![CDATA[

              import mx.rpc.events.ResultEvent;

              import mx.collections.XMLListCollection;

           

              private var xlc:XMLListCollection;

           

              private function dataFunc(evt:ResultEvent):void{

                  xlc = new XMLListCollection(evt.result..Result);

                  var myseries:ColumnSeries = new ColumnSeries();
                  myseries.dataProvider = xlc;
                  myseries.yField = "Result";
                  myChart.series.push(myseries);

              }
          ]]>
          </mx:Script>

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          1 person found this helpful