How about something like this:

(note: I've not tried it, just slapped it straight into the email)

public class MyClassThatInvokesHTTPServices {

//inner helper class.
class MyIResponder implements IResponder{
   public var f:Function;
   public var r:Function;

   public MyIResponder(r:Function, f:Function){
     this.r = r;
     this.f = f;
   }

   public function fault(info:Object):void {
       f.call(info);
   }

   public function result(result:Object):void {
       r.call(result);
   }
}

//Your handlers for service calls.
protected function resultA(result:Object){ ... }
protected function faultA(info:Object){...}
protected function resultB(result:Object){ ... }
protected function faultB(info:Object){...}

var service:HTTPService ...//assume exists, reused for various calls.

  //send for service A.
  funciton sendA(args:Object){
    service.url = "../A.html";
    service.send(args).addResponder(new MyIResponder(resultA, faultA));
  }

  //send for service B.
  function sendB(){
    service.url = "../B.html";
    service.send().addResponder(new MyIResponder(resultB, faultB));
  }


}

[snip]

>>>> --- In [email protected], "lagos_tout" <lagos.tout@> 
>> wrote:
>>>>> Hi,
>>>>>
>>>>> I'm re-using an instance of HTTPService, changing the request 
>>>>> arguments to get different responses from the server.  But I 
>> found 
>>>>> that if, for instance, I made 3 calls this way with the 
>>> HTTPService, 
>>>>> each of the 3 result handlers registered for each call is 
>> executed 
>>>>> every time a result returned.  
>>>>>
>>>>> I solved this by storing a reference to the unique AsyncToken 
>>> returned 
>>>>> by each service call and matching it to the AsyncToken 
> contained 
>>> in 
>>>>> each ResultEvent's "token" property in order to determine 
> which 
>>> result 
>>>>> handler to execute. 
>>>>>
>>>>> I'm not terribly happy with this setup.  It seems messy.  I'd 
>>>>> appreciate any suggestions on how I can reuse an HTTPService 
>>> instance 
>>>>> without ending up with long switch statements with countless 
> "if 
>>>>> thisAsyncToken then do thisHandler, else if thatAsyncToken 
> then 
>> do 
>>>>> thatHandler... and so on".
>>>>>
>>>>> Thanks much.
>>>>>
>>>>> LT
>>>>>
> 
> 
> 
> 

Reply via email to