Remotely Connect Your Flex/AIR App Without Services-Config

by Kyle Hayes on February 26th, 2008

Many developers have the question of how to define the infamous connections to the various AMF gateways to which they need to communicate through to their server-side code. The process, while usually handled through the famed services-config.xml file, can actually be handled directly in your ActionScript very easily.

The examples below are showing connecting to a AMFPHP endpoint as opposed to a ColdFusion one, only because that is what I have been learning and working on recently. For ColdFusion, simply replace the latter part of the string with /flex2gateway/

First, define a new string in your model that references the URI to which you are going to connect with your RemoteObjects:


var endpointUri:String = "http://mysite.com:8000/amfphp/gateway.php";

Then, simply define a new ChannelSet, and Channel to add to the ChannelSet that references your URI:


var cs:ChannelSet = new ChannelSet();
var customChannel:Channel = new AMFChannel("my-amfphp", endpointUri);
cs.addChannel(customChannel);

Finally, define your RemoteObject to access this ChannelSet that you just created and set the destination to the name you gave your AMFChannel:


showBusyCursor="true" />

It is as simple as that! Be sure to take out the services-config declaration in your compiler arguments to test this out appropriately.

Popular Posts

From Desktop, Flex

44 Comments
  1. Hey Kyle, the color of the string in the first line of code is impossible to read.

  2. Interesting, it must have to do with the auto-recognization of links.

  3. You forgot to add your AMFChannel to your ChannelSet :)

  4. I knew that :-P

  5. William Ukoh permalink

    Cool. Does this work with both Flex 2/Flex 3 apps?

  6. @William – Yes, it does.

  7. I have been trying to adapt this so that the ‘destination’ attribute of the RemoteObject is a variable (so i can define vars for the destination and endpoint URI), but Flex doesn’t seem to like it. Do you know how you can programmatically set the destination name ?

  8. You could probably do it using ANT

  9. True, however I am hoping I could have an external settings.xml file which will set the values at run time, not at compile time. When I put a binding expression in the destination attribute (i.e. destination="{somevar}") the compiler doesn’t complain, but at runtime I always get an error.

  10. I’m pretty sure the compiler needs to know that at runtime, hence the reasoning behind needing access to the services-config.xml or other data about the remote connection when you compile.

  11. Andrew,

    I am using the destination as a variable and the code for the same can be downloaded from http://www.hemtalreja.com

    Hope this helps.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS