When using remote objects in Flex (for BlazeDS) you may want to change the endpoint (server, port and context root) and switch between servers. This is useful if your development environment contains both testing and production servers (as it should).
The usual way is to define these settings in the Flex/Flash Builder project when the project is created but this is not easily changed once it's been set up.
An alternative way to set endpoints is is to set them via ActionScript. If you do this you can set up the project as an ordinary Flex project with no server settings.
Here's a class you can use that extends RemoteObject. It creates the endpoint in it's constructor from static constants but these could be passed in if required. It assumes that you are using the basic amf protocol over http (ie REST style interfaces) but again this is easily changed.
public dynamic class AutoEndpointRemoteObject extends RemoteObject
public static const IP:String = "x.x.x.x";
public static const PORT:String = "xx";
public static const CONTEXTROOT:String = "xxxx";
public function AutoEndpointRemoteObject(destination:String=null)
var amfPath:String = "http://" + AutoEndpointRemoteObject.IP + ":" + AutoEndpointRemoteObject.PORT + "/" + AutoEndpointRemoteObject.CONTEXTROOT + "/messagebroker/amf";
var channelSet:ChannelSet = new ChannelSet();
var channel:AMFChannel = new AMFChannel("my-amf", amfPath);
this.channelSet = channelSet;
this.endpoint = amfPath;
To use this class to call a method "myMethod" on a remote object "myObject" you would do the following.
Due to how the Flex compiler handles <mx:method>you can't use <mx:method> as a child of this class if you use it in MXML. You can only use this class via ActionScript.