2 Replies Latest reply on Jan 22, 2008 1:42 PM by ntsiii

    HTTP Service Handler Function

    mrigor
      Hello,

      I have been working with flex for a brief period of time and have had some difficulty attempting to setup a function. I would like to create a universal function to handle all of the HTTP Web Service calls that return data back to a list or datagrid. My current function is located below.

      public function HTTPServiceResultHandlerArray(event:ResultEvent,DP:String):void
      {
      if (DP == 'CP') {
      acCurrentPrograms = event.result.programs.program;
      } else if (DP == 'RP') {
      acRemainingPrograms = event.result.programs.program;
      }
      // Remove busy cursor
      CursorManager.removeBusyCursor();
      }

      As you can see I have to program for each instance. What I would like to do is to pass the ArrayColletion and event string value to the function when I make the call. Is it possible to pass a variable by reference? Is there another way to tackle the issue?

      Thanks for you help.

      Matt
        • 1. Re: HTTP Service Handler Function
          ntsiii Level 3
          Meet the AsyncToken.

          When you invoke send() on any of the RPC protocols, including HTTPService, send returns a dynamic object called an AsyncToken. You can add most anything you want to this object, including strings, and anonymous functions. In your result handler, you can access this AsyncToken object and read any values you set when sending the request.

          Since I am not comfortable with annonymous functions, I usually assign a string, like:
          var atCall:AsyncToken = myHTTPService.send();
          atCall.queryId = "SomeId";
          atCall.nextProc = "DoThisNext";
          YES, YOU ASSIGN THESE AFTER THE SEND()!

          Then in the handler function, I do:
          var atCall:AsyncToken = event.token;
          var sQueryId:String = atCall.queryId;
          switch (sQueryId){
          case "someId":
          doSomething();
          break;
          case "someOtherId":
          doSomethingelse();
          ...

          Get it? The token properties can contian references to other objects, most anything.

          Pretty useful, no? There is more detail in the docs, but who needs it?

          Tracy
          • 2. Re: HTTP Service Handler Function
            ntsiii Level 3
            You'll need to import AsyncToken