Lets say you want to call a remote function with Flex’s RemoteObject and in the Response Handler you wish to access some of the variables you used in your calling function. You could use class variables so that they are available in your Response Handler. But thats not always the preferred way.

Another option that I like to use is to define the response handler in your calling Method as a closure. That way you will have access to all variables that are in the scope of the calling method in your handler function.

Here is an example on how to achieve this:

public function callRemoteMethod( myvar:String ):void {

myRemoteObject.myRemoteFunction( myvar ).addResponder(

new ItemResponder(

function(re:ResultEvent, a:AsyncToken ):void {

//the resonder has access to myar

trace(myvar ) ; trace(re.result) ;

},

function(f:FaultEvent, a:AsyncToken):void {

Alert.show(‘An Error occurred’) ;

}

)

) ;

}