I like! This line says it all: > service.send().addResponder(new MyIResponder(resultB, faultB));
Thanks much. I think this is the solution. It meets my requirements: no long conditionals; one-to-one matching of service calls to fault/result handlers; reuse of the same service object; and, if i create a separate class (implemementing IResponder and containing it's own fault and result handlers, rather than passing it in as you've done) for each type of service call, i think i get to live another day by the OO mantra "closed to modification, open to extension". Weird though how Flex requires one to add the responder after the call is already made, don't you think? One would think the responder should be in place before the call to service.send(). Thanks again! LT --- In [email protected], shaun <[EMAIL PROTECTED]> wrote: > > > 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 > >>>>> > > > > > > > > >

