Daemonite: Flash Remoting - CFMX/FMX/Communication Archive

Daemonite: Flash Remoting - CFMX/FMX/Communication Archive


Tuesday, September 10, 2002
Flash Remoting - CFMX/FMX/Communication

The mighty Scott Barnes was asking about how to pass information back to ColdFusion via the Flash Remoting Gateway on FUGLI yesterday, read on to find out the response that I cobbled together.

In answer to Scott's question about passing information to CFMX from FMX via the gateway the first thing is to remember is that, naturally, FMX is where you would build your ui.

So in order for that to commence you need to establish a connection to the gateway itself.

Here's what I normally do when I'm setting up a Flash app that'll be using FR.

1. Include the necessary ActionScript files to enable the FR connections.

------------------------------------------------------------------

#include "NetServices.as"
#include "NetDebug.as"

------------------------------------------------------------------

2. Establish the connection to the gateway, in this example I'm checking to see if the connection exists using an if statement. I then define my gatewayConnection, and next I create a variable, "server", equal to the cfc that I'm going to call via the gateway. In this example I'm calling a cfc called "dmEmployeeData" within a directory at the webroot called "dm_FR", hence "dm_FR.dmEmployeeData".

------------------------------------------------------------------

//Establish connection to Flash Gateway
if (init == null)
{
init = true;
gatewayConnection = NetServices.createGatewayConnection("http://127.0.0.1:8500/flashservices/gateway");
var server = gatewayConnection.getService("dm_FR.dmEmployeeData", this);
}

------------------------------------------------------------------

3. Once the connection has been established you can use the "server" variable to call any function on the cfc. For example in the example above, the code is taken from the Flash Remoting tutorials on the Daemon site, I could then call a getDepartments function on the cfc using the following:

------------------------------------------------------------------

server.getDepartments();

------------------------------------------------------------------

4. If I needed to call a function on the cfc passing arguments into it as part of the call I would do that passing a Flash object as the argument of the Flash function call.

NB. Flash objects look a lot like the structures that we would usually use in CF.

Here's a couple of examples:

------------------------------------------------------------------

Flash object with one value pair, nb: the value "1" here is cast as numeric

server.getResellers({countryID:1});


Flash object with multiple value pairs, nb: the first two values cast as string

server.addEmployee(firstName:"Wally",lastName:"Wilson",age:65);

------------------------------------------------------------------

ColdFusion should then respond in whatever way that you've designed your application - for additional information, if you haven't checked it out yet, you might like to check out the tutorials on the Daemon site:

Daemon Training - Tips & Tricks link

Posted by at 08:34 PM | Permalink
Trackback: http://blog.daemon.com.au/cgi-bin/dmblog/mt-tb.cgi/39

Comments

I am mighty *roar*

I'm gonna attempt the unchartered waters, and send an array to coldfusion.

It sounds like a bold plan, but here goes nothing!

Posted by: Scott Barnes on September 19, 2002 06:44 PM

Really enjoyed visiting your site, I have added it to my bookmarks

Posted by: Jenna Jameson on March 27, 2003 11:53 PM