ASyncToken and IResponder example

My previous tutorial demonstrated the use of ASyncToken. This tutorial will expand upon that code and put the result and fault handlers into their own object implementing the IResponder interface. If you haven't done so, you should read that tutorial now. It also contains the PHP code related to this ASyncToken tutorial.

package Responders
    import mx.rpc.IResponder;
    import mx.controls.Alert;
    public class BravoResponder implements IResponder
        public function BravoResponder()
        public function result(data:Object):void
            var myData   : String  = data.result as String;
            var myLetter : String  = data.token.letter;
  "Return: " + myData, "Token: " + myLetter);	
        public function fault(info:Object):void
  "Crap, something went wrong");

This code basically implements the fault and result event handlers from the previous tutorial inside a user-defined object. Whereas the previous code had the result and fault handlers defined within the main mxml file, this example keeps things completely separate with a much better OOP implementation.

The previous example used this code

token.addResponder(new mx.rpc.Responder(onResult, onFault));

This example can add the BravoResponder like so:

token.addResponder(new BravoResponder());

See the previous tutorial to see how to create a token and where the above code would be used.


Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.