passing multiple parameters to resulthandlers in flex
Is there a way to extend the ResultEvent class in flex. i have the following code:
var token:AsyncToken = remoteObject.setQueryAndGetPromptValues('country', queryString);
token.addResponder(new mx.rpc.Responder(resultCountrySearch,faultCountrySearch));
var token:AsyncToken = remoteObject.setQueryAndGetPromptValues('company', queryString); token.addResponder(new mx.rpc.Responder(resultCompanySearch,faultCompanySearch));
so once the RPC call is executed I get a ResultEvent which is handled by resultCountrySearch or resultCompanySearch, each of which updates the 开发者_开发百科corresponding text field. I have 30 such prompts so I do not want to create 30 different handler functions. Is there a way that I could pass which text field to update to the resultHandler along with the result event.
One way is to add your variables to to the asyncToken as object properties and the use them in the resulthandler
token.myprop = myvar;
There IS a way because the Swiz library does it for you. All you have to do is call executeServiceCall(call, resultHandler, faultHandler, eventArgs)
, and the evertArgs
array is passed through as an argument to whichever handler is called.
I don't know all the implementation details, but it's an open source library, so you can have a poke around at their DynamicResponder
class (implements IResponder
) to see the Swiz approach. It's probably best to read the relevant documentation first of course (don't worry, it's short!).
Alternatively you could just use the library, though that may not be practical for your requirements.
精彩评论