An important benefit of the new and improved Flash Remoting adapter (installed with the Flex updater for ColdFusion MX 7.01, and used in conjunction with Flex 2) is the automatic conversion of objects between ColdFusion and Flex - CFCs mapped to ActionScript classes, and vice-versa.
For example, suppose you had a User.cfc in ColdFusion and a User.as in Flex. If you returned the User ActionScript class to ColdFusion what you'd get on the ColdFusion end is an instance of User.cfc. And when a Flash Remoting call returns a User.cfc (or perhaps an array of them), what you'd end up with in Flex is a User class (or an array of them).
This conversion is automatic, but there are some very specific requirements that you must meet (miss any of them any the data sent back and forth will be a generic object):
- Both the CFC and the ActionScript class must have the exact same properties (same name, same type, and same order). And yes, this does mean that you'll need to use the <cfproperty> tag in your CFC.
- The full path to the CFC is needed, and this means that you must instantiate it using a fully qualified dot notation path (even if the CFC is in the current directory where just the CFC name would usually suffice).
- The ActionScript object must be associated with the CFC using the [RemoteClass] (which expects the fully qualified path to the CFC).
The following snippets from an example application I posted demonstrate this. This first snippet is from Phone.cfc. Notice that it defines 10 properties (the code also contains over 20 methods which are not included here):
<!--- Define properties --->
<cfproperty name="name" type="string" default="">
<cfproperty name="description" type="string" default="">
<cfproperty name="price" type="numeric" default="0">
<cfproperty name="image" type="string" default="">
<cfproperty name="series" type="string" default="">
<cfproperty name="triband" type="boolean" default="false">
<cfproperty name="camera" type="boolean" default="false">
<cfproperty name="video" type="boolean" default="false">
<cfproperty name="highlight1" type="string" default="">
<cfproperty name="highlight2" type="string" default="">
<!--- Initialize vars --->
public class Phone
public var name:String;
public var description:String;
public var price:Number;
public var image:String;
public var series:String;
public var triband:Boolean;
public var camera:Boolean;
public var video:Boolean;
public var highlight1:String;
public var highlight2:String;
public function Phone()
public function toString():String
return "Phone: " + name;
// Phone class (maps to Phone.cfc)
As you can see, with a little care and planning, automatic conversion of objects back and forth between ColdFusion and Flex 2 is very doable (not to mention incredibly useful).