This is meant to test a remoting connection with a ColdFusion back-end

The ColdFsuion Code has been tested and works. Here is the cfc that I am using


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

The rest is actionscript!

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*/)

Now I am attempting to make a template for this in FDT, it works fine in the Flash IDE, but I really don’t want to use the IDE for coding, as I really like FDT for coding!

Now this is the exact code, but I will try to figure out how to use the template propties in FDT to figure out how to change the names of the function, where the cfc is to varaibales, as these will not always be the same. This is just a test to see if you were able to connect to the gateway.

This does work when I dump it into my class, but I get a starnage error

the error panel tells me (click on image for bigger image)

the part besides the template I don’t get, if I have access to the flash.net package in FDT why would I recieve these errors? Works fine in the Flash IDE, but not in FDT.

You can see the post for setting this up for the Flash IDE here
http://hawaiiflash.net/blog/post.cfm/flash-remoting Download the code put the com folder in your CF webroot, open the fla and run just tested and works fine.

UPDATE

package {
    import flash.events.NetStatusEvent;
    //import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.net.Responder;

    /**
     * @author johnbarrett
     */

    public class Remoting extends NetConnection {

        //set up the variables for the connetion and the responder
        private static var _gateway : NetConnection = new NetConnection();
        private static var _responder : Responder =new Responder(onResult,onFault);

        //use protected to not get an error
        protected var responds : Object;

        private static function onFault(responds:Object) : void {
            //loop over the fault structure
            for (var i:String in responds) {
                trace( i + ":" + responds[i] );
            }
        }

        private static function onResult(event : NetStatusEvent) : void {
            var responds : Object;
            trace(responds.toString());
        }

        // 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 gets rid of the all the errors in FDT, but I do get an warning witht he .toString();

However, when I run the example I get the compile error:

[Info] Connection to player established.

Exception fault: Error: Error #2132: NetConnection.connect cannot be called from a netStatus event handler.

    at flash.net::NetConnection/connect()
    at Remoting$cinit()
    at global$init()[/Users/johnbarrett/Documents/workspace/Remoting/src/Remoting.as:13]

 

By |2010-03-10T22:58:40+00:00March 10th, 2010|FDT, Flash, Flash Remoting|