Adobe has gone through a lot of trouble to make sure that ColdFusion and Flex play really nice together. When you pass an ActionScript object to a CFC method, CF (Using an embedded version LiveCycle Data Services ) will automatically turn that ActionScript Object into a CFC instance. When ColdFusion passes passing a CFC back to Flex, that CFC will turn into a ActionScript object.

Conceptually this is great. Unfortunately, the reality is that you must be very particular in your implementation or this will not work. If you don't set it up properly, Flex will view the result CFC as a generic Flex object, not your custom AS3 object. It took me a few days of banging on this before I got it; and I never had a problem again. I thought I would try to impart some of my wisdom.

First, you want to make sure that your AS3 object maps to the CFC on the remote server.

view plain print about
1[RemoteClass(alias="com.DotComIt.project.ClassName")]

The CFC will have to be located in the alias path in the web root. On my dev machine this is something like "C:\wwwroot\com\DotComIt\project\ClassName.cfc". Be sure that the alias is case sensitive to the directory path. Even if you're on a windows unit, case sensitivity matters.

Second, make sure that all the instance variable of the object matches is defined as a property on the AS3 object. Based on my dealing with this you can define simple properties (AKA public variables ) or complex properties (with get and set methods) and it still works. In this case I've only used get set properties sparingly. On the CF side, you want to be sure to define every property in your AS3 object using the cfproperty tag. You must be certain to retain the order of property names and the case sensitivity of each one. If not, the objects won't translate.

Even with these two items checked off, there is another item to be aware of. Often when dealing with Cairngorm I'm turning a ColdFusion query into an array of Value Objects. Each value object is mapped from a CFC to an AS3 object using the above approach. However, if an instance of the custom AS3 object is never created inside the app, then your custom objects will be returned as generic objects. So, when I'm always returning an object as an array (as oppose to an individual object), I'll often add a line of code like this:

view plain print about
1var myObject: MyCustomClass;

somewhere in the application. In Cairngorm I'll put it in the model locator; otherwise I might create it in a CreationComplete event.

I believe the reason for this is that the Flex Compiler is doing too much optimization. Even though the custom class is in my Flex project, if the compiler doesn't seen an instance of the class it removes it from the final swf. And as such, the final swf doesn't have the class definition and doesn't know what to do with it.

WebORB offers this type of functionality for technologies other than ColdFusion. I've done some work with WebORB for .NET. It might be worth noting that for the object to transfer properly from Flex to a .NET Assembly, you must add a mapping to the weborb.config file. Your custom mapping will look something like this:

view plain print about
1<classMapping>
2 <clientClass>com.DotComIt.project.ClassName</clientClass>
3 <serverClass>com.DotComIt.project.ClassName</serverClass>
4</classMapping>

The 'clientClass' is the package of the ActionScript object and the serverClass is the location of the object in your .NET assembly. The path names do not have to be identical with either technology, but I find it easy to keep things straight if they are.