3 Replies Latest reply on Aug 22, 2007 9:00 PM by ntsiii

    HTTPService: How can I clear the lastResults data

      I have:
      <mx:HTTPService id="userRequest" url="get_info.php" useProxy="false" method="GET" />

      I then have:
      <mx:DataGrid id="dgUserRequest" dataProvider="{userRequest.lastResult.users.user}" >

      I also have text:
      <mx:Label id="t1" text="{userRequest.lastResult.users.user.name}" />

      I want to be able to clear both the dataGrid and the Label by clearing the HTTPService of its last results.
      Is this possible?
        • 1. Re: HTTPService: How can I clear the lastResults data
          theLoggerGuy Level 1
          I haven't tried it, but what about userRequest.clearResult();
          • 2. Re: HTTPService: How can I clear the lastResults data
            ntsiii Level 3
            Do not bind directly to lastResult. There are sooo many reasons, and this is one.

            Declare an instance variable, bind to that, then set that variable's value in a result handler function.

            Then you can just say _xmlMyData = null.

            Also, be sure to set resultFormat="e4x" on the HTTPService. The default is "object" and you do not want that.

            • 3. Re: HTTPService: How can I clear the lastResults data
              ntsiii Level 3
              Here are som more snippets:

              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":