1 Reply Latest reply on Jul 17, 2007 5:13 PM by ntsiii

    HTTPSerice & XML -problem

    scrattis Level 1

      I have an XML-formatted data which I get from a file.
      Then when I tried to get to those values, I cant. If I trace, I can see that there are [object] [object] ...etc. But when I eg. trace children()[0] it traces nothing.

      Here Is the example XML:
      <?xml version="1.0" encoding="utf-8"?>

      If I use the data from HTTPService to populate a datagrid, data shows quite nicely.
      private var autotCol:ArrayCollection;
      autotCol = event.result.AutoLista.Auto;
      <mx:DataGrid id="dg" width="100%" height="245" rowCount="5" dataProvider="{autotCol}" itemClick="item_clicked(event)">

      Thing that I want to do, is to for loop all the child nodes (<Auto>) and do some calculations and add there one extra node for the datagrid.

      What I'm doing wrong?
        • 1. Re: HTTPSerice &amp; XML -problem
          ntsiii Level 3
          HTTPService defaults to resultFormat="object". You do not want that, you want resultFormat="e4x".

          Then, do not bind to the lastResult. Instead use a result handler function. In that function you can loop over the Auto nodes.
          var xmlData:XML = XML(event.result);
          var xlAuto:XMLList = xmlData.auto;
          for (var i:int=0;i<xlAuto.length();i++) {
          trace(xlAuto[ i ].toXMLString())

          Here are some more snippets that might help.

          Sample code using HTTPService, e4x, handler function to populate a list item.
          Also shows usage of AsyncToken.

          The DataGrid tag:
          <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>

          The HTTPService tag:
          <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

          Script block declaration:
          import mx.rpc.Events.ResultEvent;
          [Bindable]private var _xlcMyListData:XMLListCollection;

          Invoke send:
          var oRequest:Object = new Object();
          oRequest.Arg1 = "value1";
          var callToken:AsyncToken = service.send(oRequest);
          token.callId = "myQuery1";

          Result Handler function:
          private function onResult(oEvent:ResultEvent):void {
          var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
          var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
          _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
          trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
          var callToken:AsyncToken = oEvent.token;
          var sCallId = callToken.callId; //"myQuery1"
          switch(sCallId) {
          case "myQuery1":