3 Replies Latest reply on Feb 12, 2008 7:47 AM by derm116

    error displaying xml in combobox

    derm116 Level 1
      Hi all,

      I'm trying to take in some xml over httpservice and display part of it in a combobox! However, all that comes up in my combobox is [object, Object]?? Does anyone know why this is and how I can fix it?

      The following is my code


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:comp="components.*" width="400" height="360" viewSourceURL="srcview/index.html">
      <mx:Script>
      <![CDATA[

      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.http.HTTPService;
      import mx.utils.XMLUtil;
      import mx.collections.ArrayCollection;

      [Bindable]
      public var myXML:XML ; //Holds the XML result sent back

      //Array that holds the version name
      [Bindable]
      public var versionData:Array ;

      /*Creates an HttpService object and executes the send method*/
      public function useHttpService():void {
      var params:Object = new Object() ;
      var service:HTTPService = new HTTPService(); //create an HTTPService object named service

      //set the properties of the service object
      service.url = " http://localhost:9080/oneClickInstall/sample/XMLAppListAction"; //url is where to connect
      service.method="get";
      service.addEventListener("result", httpResult); //identify which function will handle the results whenever the results come back
      service.addEventListener("fault", httpFault); //identify which function will handle an error
      service.resultFormat="e4x"; //format the result returned as XML e4x format
      service.send(params); //connect to the URL and pass the name-value pairs int The parameters object
      } //end function useHttpService

      /*handle result returned by useHttpService*/
      public function httpResult(event:ResultEvent):void {
      //Object to take in the result
      var result:Object = event.result
      //Object to hold the array items
      var item:Object;

      //New array
      versionData=new Array();
      myXML = new XML(result); //create an XML object

      //Create an XML list to hold all the version attributes ie name
      var versionAttributes:XMLList = myXML.Version.Release.attributes();

      var i:int = 0;
      //Loop through the list, adding each value to versionData
      for each (var nameElement:XML in versionAttributes){
      //Create a new item object
      item = new Object();
      //Add name Element as the label
      item.label=nameElement;
      //Add name Element as the data
      item.data=nameElement;
      //Add the item to the array
      versionData = [{label:item.label, data:item.data}];
      i++;
      }
      } //end function httpResult

      //Called whenever a service fault is encountered
      public function httpFault(event:FaultEvent):void {
      currentState = 'error state'; //Change to the error view
      } //end function httpFault
      ]]>
      </mx:Script>

      <mx:Panel layout="absolute" backgroundColor="#8396a9" borderStyle="solid" left="10" top="10" width="380" height="337" cornerRadius="20" borderThickness="2" borderColor="#ffffff" id="panel1">
      <mx:Button x="138" y="10" label="Submit" click="useHttpService()" id="submitBtn"/>
      <mx:Label x="10" y="57" text="Version:" width="97" fontFamily="Verdana" fontSize="14" color="#ffffff" id="versionLabel"/>
      <mx:TextArea x="29" y="104" width="282" height="179" id="xmlText"
      text="{myXML.toXMLString()}" fontFamily="Verdana" fontSize="12" color="#000080" backgroundColor="#8396a9"/>
      <mx:ComboBox x="138" y="59" dataProvider="{versionData}" id="versionBox" prompt="Please select a version..."/>
      </mx:Panel>
      </mx:Application>


      Any help would be greatly appreciated! Thanks in advance1

      Derm