Here is something I have just added into my book in the Flash Remoting chapter and wanted to share with you :)

As you may know, no wrapper class is embedded into Flash CS3 for your remoting calls, you have to use the raw NetConnection class which is not very practical in a large project.

I wanted a simple class to call some remote methods in Flash CS3 like the RemoteObject class does in Flex, and like the Service class we had in Flash 8. I came across Danny Patterson remoting framework which is very smooth, but noticed that it was not working the way I wanted it.

So I created a wrapper around the NetConnection object which behaves like the Service class we used to have with a PendingCall assigned to each remote procedure.

Here is how you create the remote service :

// create a remote object (Singleton)
var service:Service = Service.getInstance();

// set the required infos
service.setRemoteInfos ("http://www.bytearray.org/wp-content/projects/remotingservice/amfphp/gateway.php",
"org.bytearray.HelloWorld",
ObjectEncoding.AMF3 );

Then you call the remote method, this returns you a PendingCall object :

// call the remote method
var rpc:PendingCall = service.sayHello("Hello there ?");

The PendingCall object is dispatching two events, ResultEvent.RESULT and FaultEvent.FAULT :

// call the remote method
var rpc:PendingCall = service.sayHello("Hello there ?");

// wait for the result event (everything is ok)
rpc.addEventListener ( ResultEvent.RESULT, success );

// wait for the fault event (an error occured)
rpc.addEventListener ( FaultEvent.FAULT, error );

// get the result
function success ( pEvt:ResultEvent ):void
{

// output : you said : Hello there ?
trace( pEvt.result )

}

// get the result
function error ( pEvt:FaultEvent ):void
{

trace( pEvt.fault.description )

}

You can change the service or gateway at any time :

service.service = "org.bytearray.AnotherService";
service.gatewayURL = "http://www.myserver.org/amfphp/myOtherGateway.php";

Or authenticate yourself with some credentials :

service.setRemoteCredentials ("bob", "groove");

Sources and file examples available here

Update (05/04/09) : Version 0.2 : Changed the Service implementation as a Singleton.