Follow Flex After Dark on Twitter

Responder

A Responder is simple class encapsulating the handling of a Remote (asynchronous) call and its result and/or fault. A Responder class will implement the mx.rpc.IResponder interface.

A Responder object has two important methods:

  • result() - function receives a ResultEvent
  • fault() - function receives a FaultEvent

AsyncToken and Responders

Responders are usually used with AsyncTokens for asynchronous call handling.

AsyncResponder (mx.rpc.AsyncResponder)

AsyncResponder is a convenient implementation of the IResponder interface in the mx.rpc package.

The AsyncResponder constructor takes two arguments, both of them functions: a result handler and a fault handler.

Create an AsyncResponder instance:

   // call the HTTP Service's send() to invoke the request, a token is returned
   var token:AsyncToken = http.send();
   
   // setup responder (resultHandler and faultHandler functions) and add to token
   var responder:AsyncResponder = new AsyncResponder( resultHandler, faultHandler );
   token.addResponder( responder );

The resultHandler and faultHandler arguments passed into the constructor above are both functions with the following signatures:

   public function resultHandler( event:ResultEvent, token:Object=null ):void
   {
      Alert.show( "RESULT: "+ event.result as String );
   }
   
   public function faultHandler( event:FaultEvent, token:Object=null ):void
   {
      Alert.show( "FAULT: " + event.fault.message );
   }

Both the result and fault handler methods of an AsyncResponder accepts two arguments: the event and the token.

Related Docs:

Related Docs
Recent Docs
Random Docs