Flash Remoting in AS2: RelayResponder2

Flash MX 2004 with ActionScript v2.0 introduced enhanced syntax checking. For example, if you have a function in your class, and you mispell it, the compiler will throw an error, helping you easily find and correct the answer so your code will run as expected.

The AS2 classes for Flash Remoting do not take advantage of this fact for RelayResponders. I fixed that. Instead of passing in strings for your result and fault functions, you can pass in the functions themselves, much like you do for the first format setInterval, or when utilizing the Delegate class.

What’s different from the original (mx.rpc.RelayResponder)? Only that the __onResult and __onFault functions are now datatyped as Function vs. String, and called via Function.call(scope, param) vs. scope[string](param).

import mx.rpc.Responder;

class mx.rpc.RelayResponder2 extends Object implements Responder {

private var __obj:Object;
private var __onFault:Function; private var __onResult:Function;

function RelayResponder2( resp:Object, resultFunc:Function, faultFunc:Function ) {
__obj = resp;
__onFault = faultFunc;
__onResult = resultFunc;

function onFault( fault:mx.rpc.FaultEvent ):Void{
__onFault.call(__obj, fault);

function onResult( result:mx.rpc.ResultEvent ):Void {
__onResult.call(__obj, result);

4 Replies to “Flash Remoting in AS2: RelayResponder2”

  1. Jesse.

    Prob. not the exact right place to post, but thought I’d try anyway, seeing as I need a higher brain source :)

    Is there anyway to pass arguments into the onResult and onFault functions from a relayResponder? I know a resultEvent and faultEvent object get passed respectively, but what if you wanted to pass custom params to the functions as well?


    pc.responder = new RelayResponder2(this, getSome_Result(aNum, aVar2), gen_Fault());

  2. You mean like VB6 static variables? Naw… the onFault/onResult are passing in what the webservice sends back. Unless you intercept those messages, no go.

    What problem are you trying to solve? If you can’t have the webservice return what you need, is it merely a client problem remembering context of the call? Like, ‘I need to know this call has this ID…’ type of deal? Is that why you want the result to have some data?

  3. Flash remoting help seems to be few and far between. Especially when trying to use / learn AS2 with remoting.

    Hopefully you guys can help me with a question related to the above topic.

    I would like to create a central class for all the remoting services.. Example: I have a service that returns a custom java object. This object my be needed in several places in the app. So I don’t want to create a connection and everything each time I need this data. If I place the service in its own class I’m having alot of trouble returning the result to the calling class. Any suggestions? Some people call this a service proxy. Thanks!

  4. Typically what I do is use some AS2 modifications of my Remoting queue. It merely queues up Remoting calls so I can see them happen 1 after the other, and if 1 messes up, I can see which one it is. This also ensures I get timeouts since there are rare cases where onFault/onStatus doesn’t get called.

    Seondly, yes, I’ll have a Proxy class. First is a DataAccess class. This has all the Remoting logic, and ties in with the Model/ValueObjects passed in form the server (Java or PHP or .NET). It’ll generate events when it gets data back from the server. You MUST pick up the data from exposed public properties (getter/setters). Since the DataAccess knows how it’s really handled, it only exposes a generic type to the application in case something changes (switch from PHP to Java, or changed array to recordset). The Proxy class is merely a global class; global in that it’s the main Model in Flash terms, and this Proxy class implements your standard ‘login’, ‘getUserData’ etc. Whether or not those methods are actually implemented on the server doens’t matter. The point here is I can either call methods to update my data, or get responses. This Proxy class could also be your DataAccess class; depends on how tightly coupled you want things to be. In cases where FLash is merely displaying data, this is typically how I’ll do it because all I do is:

    – get a RecordSet/DataSet from the server
    – tie this model object to a View (say a DataGrid via the Controller)
    – any time the data updates, it generates a model changed, which in turn updates the View (DataGrid)

    This update can be triggered by a new RecordSet from the server, a DataAccess class actually generating the event, or the Controller calling it manually.

Comments are closed.