0 Replies Latest reply on Oct 2, 2010 5:30 AM by sgfone

    How do I initialize an array after getting xml data via httpservice?

    sgfone

      I am having a problem trying to initialize an array with data from an external xml file obtained via httpservice.  Any help/direction would be much appreciated.  I am using Flex 4 (Flash Builder 4).

      Here is my xml file (partial):

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <Root>
          <Row>
              <icdcodedanddesc>00 PROCEDURES AND INTERVENT</icdcodedanddesc>
          </Row>
          <Row>
              <icdcodedanddesc>00.0 THERAPEUTIC ULTRASOUND</icdcodedanddesc>
          </Row>
          <Row>
              <icdcodedanddesc>00.01 THERAPEUTIC US VESSELS H</icdcodedanddesc>
          </Row>
          <Row>
              <icdcodedanddesc>00.02 THERAPEUTIC ULTRASOUND O</icdcodedanddesc>
          </Row>

      </Root>

       

      Here is my http service call:

      <s:HTTPService id="icdcodeservice" url="ICD9V2MergeNumAndDescNotAllCodes.xml"
                             result="icdcodesService_resultHandler(event)" showBusyCursor="true"  />

      (I have tried resultFormat using object, array, xml).

       

      I am using this following Tour de Flex example as the base -http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=1;sampleId =70500

      and updating it with the httpservice call and result handler.  But I cannot get the data to appear - I get [object Object] instead.  In my result handler code  I use "icdcodesar = new Array(event.result.Root.Row);"  and then "icdcodesar.refresh();".

       

      The key question is: How to I get data from an external xml file into an array without getting [object Object] when referencing the array entries.  Thanks much!

       

      (Tour de Flex example at http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=1;sampleId =70500  follows)

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  
                     xmlns:s="library://ns.adobe.com/flex/spark" 
                     xmlns:mx="library://ns.adobe.com/flex/mx" 
                     xmlns:local="*"
                     skinClass="TDFGradientBackgroundSkin" 
                     viewSourceURL="srcview/index.html">
          
          <fx:Style>
              @namespace s "library://ns.adobe.com/flex/spark";
              @namespace mx "library://ns.adobe.com/flex/mx";
              @namespace local "*";
              
              s|Label {
                  color: #000000;
              }
              
          </fx:Style>
          
          <fx:Script>
              <![CDATA[
                  
                  import mx.collections.ArrayCollection;
                  
                  private var names:ArrayCollection = new ArrayCollection( 
                      ["John Smith", "Jane Doe", "Paul Dupont", "Liz Jones", "Marie Taylor"]);
                  
                  private function searchName(item:Object):Boolean
                  {
                      return item.toLowerCase().search(searchBox.text) != -1;
                  }
                  
                  private function textChangeHandler():void
                  {
                      names.filterFunction = searchName;
                      names.refresh();
                      searchBox.dataProvider = names;
                  }
                  
                  private function itemSelectedHandler(event:SearchBoxEvent):void
                  {
                      fullName.text = event.item as String;    
                  }
                  
              ]]>
          </fx:Script>
          
          <s:layout>
              <s:HorizontalLayout verticalAlign="middle" horizontalAlign="center" />
          </s:layout>
          
          <s:Panel title="Components Samples"
                   width="600" height="100%"
                   color="0x000000" 
                   borderAlpha="0.15">
              
              <s:layout>
                  <s:HorizontalLayout horizontalAlign="center" 
                                      paddingLeft="10" paddingRight="10" 
                                      paddingTop="10" paddingBottom="10"/>
              </s:layout>
              
              <s:HGroup >
                  <s:Label text="Type a few characters to search:" />
                  <local:SearchBox id="searchBox" textChange="textChangeHandler()" itemSelected="itemSelectedHandler(event)"/>
              </s:HGroup>
              
              <mx:FormItem label="You selected:" >
                  <s:TextInput id="fullName"/>
              </mx:FormItem>
              
          </s:Panel>
          
      </s:Application>