FDT Remoting Template

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">

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

// 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.


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;

        // name the default cf test server on this machine


        // 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]


4 Replies to “FDT Remoting Template”

  1. It’s strange that this compiles in the Flash IDE 🙂
    The Flash IDE compiler must be different to the Flex SDK compiler that we use in FDT.
    The Flex Compiler will not let you compile this code because there’s a scope issue.

    The fix:
    Make your public field variable static (public static var gateway …)

    The explanation:
    This code: gateway.connect() in line 27 is not inside a function scope.
    It’s part of the static initializer scope, a special scope in AS 3 that only has access to static fields and functions.

    FDT just tells you what’s wrong in you code, no problem with the template 🙂
    -FDT Team

  2. Minimalist Example – No Comments – sorry

    package com.iDesignMedia.iVideo{
       import com.iDesignMedia.iRules.IVideo;
       import flash.display.DisplayObjectContainer;
       import flash.events.EventDispatcher;
       import flash.events.NetStatusEvent;
       import flash.media.Video;
       import flash.net.NetConnection;
       import flash.net.NetStream;
       public class IDMVideoPlayer extends EventDispatcher implements IVideo{
          private var netStream:NetStream;
          private var netConn:NetConnection;
          private var _info:String
          private var meta:Object;
          public function IDMVideoPlayer(video:Video,parent:DisplayObjectContainer,width:Number=320,height:Number=240){
           netConn = new NetConnection();
           netConn.addEventListener(NetStatusEvent.NET_STATUS, videoStatus, false, 0, true);
           meta = new Object();
           meta.onMetaData = onMetaData;
           netStream = new NetStream(netConn);
           netStream.client = meta;
           netStream.addEventListener(NetStatusEvent.NET_STATUS, videoStatus, false, 0, true);   
          public function Play(src:String,isLoaded:Boolean=false):void{
           isLoaded = true;
          public function Pause():void{
          public function Stop():void{
          override public function toString():String{
           return this._info
           public function onMetaData(_meta:Object):void{
        this.meta = _meta;
          private function videoStatus(evnt:NetStatusEvent):void{
           _info = evnt.info.code
    switch (evnt.info.code) {
    case &quot;NetConnection.Connect.Success&quot;:
    case &quot;NetStream.Play.StreamNotFound&quot;:
    trace(&quot;Stream not found: &quot;);
    case &quot;NetStream.Play.Stop&quot;:

    now you eventually create function for seeking and adding adverts to the video player. check out my AIR application -> http://bit.ly/bukdUK

  3. @Michael Plank Thanks so much for your reply, and for teaching me about scopes too!

    Yes I know that if there are errors in the code the Flex SDK will not let you compile and run the code!

    I have changed the variables to:

    private static var _gateway : NetConnection = new NetConnection();

    and this does fix the problem. There is still some differences that I need to get used to.

    The good news is that when I was using Quick Fix in FDT it corrected me, I love Quick Fix, it is great`-`

    Thanks so much!

Leave a Reply

Your email address will not be published. Required fields are marked *