2 Replies Latest reply on Jul 25, 2007 12:03 AM by Kai001

    Load HTTPService into List

    Kai001
      I was curious as to how to load up an xml file through an HTTPService into a list box.
      I have a properly formatted XML file but this does not work:
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="search.send();" layout="absolute" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="151">
      <mx:HTTPService id="search" url=" http://www.aspergercolony.com/AnimalCrossingMag/Guide/Keywords1.php" resultFormat="object" useProxy="false" showBusyCursor="true"/>
      <mx:List x="10" width="130" top="10" bottom="56" dataProvider="{search.lastResult.Pages}" labelField="@label"/>
      </mx:Application>

      It says "[Object] [Object]" in the list box.
        • 1. Re: Load HTTPService into List
          ntsiii Level 3
          The problem is probably with your dataProvider reference or labelField specification.

          But it is very hard to debug code written like that. Below are some snippets that are a much better way to do this.

          Tracy
          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":
          doQuery2();
          break;
          ...
          }
          }//onResult
          • 2. Re: Load HTTPService into List
            Kai001 Level 1
            Well, I typed what you put except it says:
            "1046: Type was not found or was not a compile-time constant: ResultEvent."

            Why does it say this?

            Though thanks for the help so far!