MinimalRemoting: Simple Remoting Class without the Bells and Whistles [AS3] · Jan 5, 08:05 PM

Mostly based on two other public projects, this class distills AMF remoting in AS3 down to a class that extends EventDispatcher. Code was ripped from Josh Strike’s remoting package and also from ProDevTips.

Download MinimalRemoting Now

Example Usage

We need two imports:


import com.afw.remoting.MinimalRemoting;
  import com.afw.remoting.RemotingEvent;

Instantiate MinimalRemoting (in this case we are connecting to the amfphp gateway on the localhost server):

var remoting:MinimalRemoting = new MinimalRemoting("http://localhost/amfphp/gateway.php");

Then add the three event listeners (we choose to treat FAILED and NET_STATUS_FAILED the same way):


_mr.addEventListener(RemotingEvent.RESULT, onComplete);
 _mr.addEventListener(RemotingEvent.FAILED, onFailed);
 _mr.addEventListener(RemotingEvent.NET_STATUS_FAILED, onFailed);

Now we can call our remote function:

remoting.call("MyClass.myMethod", "arg1", "arg2");

One of the following event handlers will take care of the rest:


private function onFailed(e:RemotingEvent):void {
	// do something with e.result
  }

private function onComplete(e:RemotingEvent):void {
	// do something with e.result
  }

Using RemotingEvent

In your event handlers, use the RemotingEvent’s result property. The result property of a RemotingEvent object will contain either a “deserialized” version of a successful result or the failure information for an unsuccessful result.

If you are returning a RecordSet from your server, the result woill be an Array, so you should cast the result object as an Array. If your client expects a scalar value, String or Number simply cast the result object to that type.

Documentation added 01.07.09

Goto MinimalRemoting Documentation
… you should still check out the source though there are additional comments there that should help.

— Pickle

---

Comment

Textile Help