Connecting Abobe AIR (beta) to Coldfusion via mx:RemoteObject

While Flex 3 and AIR are still in beta, there are lots of little bugs and quirks that need to be worked around. Today I was porting over a Flex application to AIR, and received an error whenever using mx:RemoteObject. It looked something like the following:

[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://myApp-debug.swf/flex2gateway/'"]

I searched for hours and hours trying to find out why my application worked correctly as a regular Flex application but not as an AIR app. I finally stumbled upon the solution and I thought I would share... in order to save everyone else the same headache. The key is to explicitly specify the endpoint attribute in the RemoteObject tag. If you are testing locally it may look something like this:

<mx:RemoteObject id="AIR_Service"
     destination="ColdFusion"
     showBusyCursor="true"
     endpoint="http://localhost:8500/flex2gateway"
     source="myApp.cfc.cfcName">

This is something I hope Adobe will fix before the official release of both these applications, but in the meantime, here is your workaround.

Dynamic Identifiers In ActionScript 3.0

I came across a problem in Flex the other day where I was trying to dynamically identify an image with ActionScript. I'll spare you the programmatic details, all you need to know is that Coldfusion returns a string that corresponds to the name of an image inside my Flex application. The image name is then used to modify the image object with the corresponding ID.

Now, I know I could have accomplished my goal by using a Switch statement but the number of images in the application would have made the code tedious to write and hard to maintain. So after much searching I found how to dynamically identify objects in my flex application.

Here is an example of how to change the source of an image, where the image's ID is produced dynamically.

SAMPLE CODE:
// if the object is in the same component, use THIS scope
this[imageName].source = "images/newImage.jpg";
// or if the object is part of a sub-component, use the component's ID as the scope
subComponentID[imageName].source = "images/newImage.jpg";

I hope this simple example is enough to clarify how to dynamically refer to an ID of an object in ActionScript 3.0; I did a lot of googling before I figured out the syntax for this - even though it's rather simple. So I hope this is enough to save some of you a bit of searching.

BlogCFC was created by Raymond Camden. This blog is running version 5.7.002.