Hello and thanks in advance for any help you can provide this flex
newbie.

I'm trying to create a simple AdvancedDataGrid that displays XML data
from a web service I wrote.  The XML file looks like:

<dashboard>
     <rollup>
        <period>2008-12-03 01:00:00</period>
        <period_sse>1228266000</period_sse>
        <country>
            <ccode>PH</ccode>
            <detects>1</detects>
        </country>
        <country>
             <ccode>GB</ccode>
             <detects>50</detects>
        </country>
     </rollup>
     <rollup>
          <period>2008-12-04 03:00:00</period>
          <period_sse>1228359600</period_sse>
          <country>
               <ccode>PH</ccode>
               <detects>18</detects>
          </country>
     </rollup>
</dashboard>

My Flex 3  MXML app is:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute"
     creationComplete="init()">
     <mx:Script>
         <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.rpc.events.ResultEvent;
         import mx.rpc.events.FaultEvent;
         import mx.controls.Alert;

         [Bindable] public var dataServiceURL:String =
"http://dashboard-dev/cgi-bin/dataService.pl?type=countrystats";;
         [Bindable] public var chartValues:ArrayCollection;

         public function init():void
         {
             countries_rpc.send();
         }
         public function handle_xml(event:ResultEvent):void
         {
             var xmlData:XML = event.result as XML;
             var newData:Array = parseXmlToArray(xmlData);
             chartValues = new ArrayCollection(newData);
          }

         public function handle_fault(event:FaultEvent):void
         {
             Alert.show(event.fault.faultString, "Error");
         }

         private function parseXmlToArray(xmlData:XML):Array
         {
             var newData:Array = new Array();

             for each (var rollup:XML in xmlData.rollup) {
                 var carray:Array = new Array();
                 for each (var country:XML in rollup.country) {
                     carray.push({
                         ccode: country.ccode,
                         detects: country.detects
                     });
                 }
                 carray.sortOn("ccode");
                 newData.push({
                     period: rollup.period,
                     period_msse: rollup.period_sse*1000,
                     children: carray
                 });
             }
             newData.sortOn("period_msse");
             return newData;
         }
         ]]>
     </mx:Script>
     <mx:HTTPService id="countries_rpc" url="{dataServiceURL}"
       result="handle_xml(event);" fault="handle_fault(event);"
resultFormat="e4x" />

     <mx:AdvancedDataGrid id="countrystatgrid" width="50%" height="50%">
         <mx:dataProvider>
             <mx:HierarchicalData source="{chartValues}"  />
         </mx:dataProvider>
         <mx:columns>
             <mx:AdvancedDataGridColumn dataField="period" />
             <mx:AdvancedDataGridColumn dataField="ccode" />
             <mx:AdvancedDataGridColumn dataField="detects" />
         </mx:columns>
     </mx:AdvancedDataGrid>
</mx:Application>

When I run this the AdvancedDataGrid is displayed but no data is shown. 
In the debugger, I can see chartValues and the data from the webservice
appears to be correctly stuffed into it.

Can anyone point me in the right direction? Thanks!
Todd


Reply via email to