Begining Flex with Flash Remoting - Part 1
A friend of mine was telling me about the problem he was having getting Flex to communicate with CF. While it is not difficult in and of its self, the problem is that there are several ways to do it and doing some combination of them will not work. Coming from a Flash background, I am most comfortable/familiar with the Remoting method, so that is what I will demonstrate.
Step 1. Configure CF Server
If you are using CF 7 (or earlier?), there is no configuration to do. However, with CF8, flash remoting is turned off by default. So you'll need to turn it on in the administrator. It is under "Data & Services -> Flex Integration." Make sure the box labeled "Enable Flash Remoting Support" is checked. You may also need to enable flash remoting to a web service. Adobe has a step-by-step here (its only 5 steps). I had to do this extra step to get Flash Remoting from Flash to work, so it may or may not apply here.
Step 2. Write a CFC
Here is my simple test cfc.
<cffunction name="test" access="remote" displayname="test" returntype="any">
<cfset string="This is what we are going to return" />
<cfreturn string/>
</cffunction>
</cfcomponent>
Lets take a look at a few key points. Just like any cfc, there needs to be a component declaration and a function. However, function access MUST be set to remote. Don't worry about security at this point. Later in this series, I'll explain why this is not a security hole.
Step 3. Write Flex
Here is what my mxml file looks like
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:RemoteObject id="myCfc" destination="ColdFusion" source="basicRemoting.flexActions" showBusyCursor="True">
<mx:method name="test" result="test_Result(event)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.utils.ObjectUtil;
public function callTest():void{
myCfc.test();
}
public function test_Result(e:ResultEvent):void{
Alert.show(e.result.toString(),"Hey, look at me")
}
/**/
]]>
</mx:Script>
<mx:Panel y="102" width="520" height="299" layout="absolute" horizontalCenter="0">
<mx:Button x="10" y="99" label="Load A String" id="getText" click="callTest()"/>
</mx:Panel>
</mx:Application>
Let's examine this code. At the top is all of the standard Flex declarations.
Next is the RemoteObject tag. The id attribute is id of the object in Flex. This is how you will reference it later.
The destination is what you are calling (i.e. ColdFusion).
The source is where the cfc is located. This is the path (in dot notation) from the webroot of ColdFusion. So on my machine, I have [path to webroot]\basicRemoting\flexActions.cfc. This gets represented as "basicRemoting.flexActions" (Note: remember that actionscript is case sensitive).
Finally, showBusyCursor=true. This will show the busy cursor while the call is processing.
Next we have the method tag. This is the name of the method that we want to call. The call is not made here, it is only defined. Next we have the result. This is the name of the function that will be called once the result is received (i.e. where to process the result)
Now we look at the script.
We need to import some remoting and alert stuff at the top. Next we create a function to call the myCfc.test(). This will be called when the mouse is clicked (defined below)
The next function is where the result is processed. The result is an event. We throw an alert to show the result part of that event, and because we are in Flex, we must convert it to a string to display it.
Below that is a panel with a button to call the myCfc.test() function.
That's it. Pretty straight forward. In part 2, I will demonstrate how to process complex results (i.e. Structs, queries) and bind them to dataGrids and the like. So stay tuned!

I'm getting the error: [RPC Fault faultString="[MessagingError message='Unknown destination 'ColdFusion'.']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'ColdFusion'"]
Can I send you my code so you help me troubleshooting it ?
Thanks,
Ricardo
Yes and I got the same error about not finding destination Coldfusion .
I will send you my code.
Thanks,
Ricardo