Setting up Flash Remoting with AS 3 & ColdFusion

/, ColdFusion, Flash Remoting/Setting up Flash Remoting with AS 3 & ColdFusion

Setting up flash remoting with actionscript 3.0 and ColdFusion
Create a fla, call it remoting(or something that makes sense to you).

In the actions, type the following code

import flash.net.*;
var gateway:NetConnection = new NetConnection();
var responder:Responder=new Responder(onResult,onFault);

function onResult(responds:Object):void {
    trace("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 cf test server on this machine
gateway.connect("http://localhost/flashservices/gateway/");

// name of the cfc and the function in it that you want to hit in dot notation
gateway.call("com.cfcs.getTest.getTestConn", responder/*this is where any arguments to the remote call go*/);

The cfc lives on my localhost/com/cfcs/gettestConn.cfc

The cfc will look like this

<cfcomponent displayName="getTest">
  <!--- Establish a Flash Remoting Connection --->
  <cffunction name="getTestConn" access="remote" returnType="string" output="true">
    <cfreturn "....connection successful">
   </cffunction>
 </cfcomponent>

When you run your flash file you should see this in the output window

download project

Move com folder to your ColdFusion localhost host, if you are running the default set up you will need to change the port to 8500. Then run the fla file, you should be fine, with flash & ColdFusion working together!

Any question, problems? Let me know I will try to help.
I will posting another example on how to display the results from your cfc, and later how to pull database results into your flash movie as well.

By | 2009-11-20T07:52:24+00:00 November 20th, 2009|Actionscript 3.0, ColdFusion, Flash Remoting|1 Comment

About the Author:

One Comment

  1. Bryan Rice September 22, 2010 at 4:09 pm

    Do you know how to do the AS2 equivalent of setCredentials in AS3 so that Flash app can remote to a CFC secured with CFLOGIN. I know, I know most people don’t use cflogin, etc. but this app does and I am trying to get a Flash app targeting Flash Player 10.1 to be able to remote to a cfc that lives under an Application.cfc that uses CFLOGIN and roles to secure the application.

    This used to be easy in AS2: http://kb2.adobe.com/cps/186/tn_18684.html

    I think the trick is to add a header somewhere, but I have no luck. Do you have any idea?

    Thanks!!

Leave A Comment