Setting up your connection with Flash & ColdFusion.
I have been asked a few times on how to connect Flash & ColdFusion for remoting.
Setting up Flash Remoting with ActionScript 3.0 and ColdFusion is easy.
Create a fla, call it connection. and create a ColdFusion component(cfc) called getTest.cfc.
In the getTest.cfc use the following code
<cfcomponent displayName="getTest"> <cffunction name="getTestConn" access="remote" returnType="string" output="true"> <cfreturn "connection to localhost was made!"> </cffunction> </cfcomponent>
This CFC sets up the connection, and returns a string.
In the actions pannel of your fla, type the following code:
import flash.net.NetConnection;
import flash.net.Responder;
var gateway:NetConnection = new NetConnection();
var responder:Responder=new Responder(onResult,onFault);
function onResult(responds:Object):void {
trace("cfc result "+" --"+" "+responds.toString());
//message.text= "cfc result "+"-- "+" "+responds.toString();
}
function onFault(responds:Object):void {
//loop over the fault structure
for (var i:String in responds) {
trace( i + ":" + responds[i] );
}
}
// name the default gateway on this machine. if you are using the default ColdFusion server use port 8500
gateway.connect("http://localhost/flashservices/gateway/");
// name of the cfc and the function
gateway.call("getTest.getTestConn", responder);
In the actions we are importing the necessary classes, setting up the variables. Then we create the function onResult and onFault. Then we define the gateway, which is http://localhost/flashservices/gateway/ or http://localhost:8500/flashservices/gateway/ for the default ColdFusion server.
Finally we call the function that we want to return in the CFC. In the above example I have the message text field commented out, but in the download it is working so you can see an example of this running.
Feel free to download the zip, and if you have any questions, leave a comment or get a hold of me :)
+