RemoteObject Configuration

For Flex developers it is much more natural to use the RemoteObject ActionScript API for accessing server-side objects instead of the pure Actionscript approach using NetConnection. Despite PyAMF currently not supporting the use of server-side Flex configuration files (like services-config.xml and remoting-config.xml), you can still use a RemoteObject within your Flex/PyAMF applications via programmatic configuration.

Here is how to wire up a RemoteObject programmatically:

// Create the AMF Channel
var channel:AMFChannel = new AMFChannel( "pyamf-channel", "http://localhost:8080/services" );

// Create a channel set and add your channel(s) to it
var channels:ChannelSet = new ChannelSet();
channels.addChannel( channel );

// Create a new remote object and add listener(s)
var remoteObject:RemoteObject = new RemoteObject( "EchoService" ); // this is the service id
remoteObject.channelSet = channels;
remoteObject.echo.addEventListener( ResultEvent.RESULT, onEchoComplete );

// Make a call to the remote object
remoteObject.echo( "Hello World" );


// Here is the result event listener
private function onEchoComplete( event:ResultEvent ):void 
{
  Alert.show( event.result.toString() );
}