Flex RemoteObject and ColdFusion Components

I am not a CF expert. So when I was asked to provide a sample program showing how to use ColdFusion Components (CFCs) from Flex, I decided it was time to learn more about Flex’s big brother.

I’m sure a lot of you will roll your eyes at the simplicity of this, but if are just getting started combining the technologies, this should be a big help.

First, define your CFC. I won’t go into the details about that, there are plenty of books on the subject. Here is a simple CFC to illustrate this example:

 <cffunction name="getdata" access="remote" returnType="any">
    <cfset myArray = ArrayNew(1)>
    <cfset myStruct = StructNew()>
    <cfset myStruct.fruit = "Apples">
    <cfset myStruct.quantity = 1245>
    <cfset myArray[1] = myStruct>

    <cfset myStruct = StructNew()>
    <cfset myStruct.fruit = "Oranges">
    <cfset myStruct.quantity = 5601>
    <cfset MyArray[2] = myStruct>

    <cfreturn myArray>

Know where your ColdFusion server is installed. For me, it is at http://localhost:8101/cf6 with /cf6 being the context root.

My CFC is in the file: cfdocs/petersamples/cfc/flextest.cfc

Know where your Flex server is installed. For me, it is at http://localhost:8700/flex with /flex being the context root.

In my Flex application I defined the following tag:

<mx:RemoteObject id="ro"
      <mx:method name="getdata" />

The endPoint is set to the Flash Remoting gateway that comes built into ColdFusion. The source points to the CFC starting just below the context root (/cf6).

The method names the cffunction(s) in the CFC.

At this point, you treat the CFC as you would any other RemoteObject: invoke the function (eg, ro.getdata(parameters)) and handle the result (eg, {ro.getdata.result}).

2 Responses to Flex RemoteObject and ColdFusion Components

  1. PaulH says:

    good idea to make those vars private:

    otherwise you could be in for some voodoo bug hunting.

  2. Clint says:

    o.getdata(parameters) doesn’t work. Maybe you should test and elaberate passing parameters TO the cfc since this is the MOST important thing about remoting. Hell, I can’t get it to work for nothing!!!!