User Guide

Table Of Contents
102 Chapter 6: Using Flash Remoting with ColdFusion MX
You access x and y in your ColdFusion page using ColdFusion array and structure notation,
as follows:
<cfset arrayElement1=Flash.x[1]>
<cfset arrayElement2=Flash.x[2]>
<cfset structElement1=Flash.y.zero>
<cfset structElement2=Flash.y.one>
You can pass ActionScript objects to ColdFusion pages. The following ActionScript defines
an object:
var myObj:Object = new Object();
myObj.x = "one";
myService.myMethod(myObj);
In ColdFusion, you access the object elements using named parameters in the Flash scope,
as follows:
<cfset p1=Flash.x>
Returning results to ActionScript
In ColdFusion pages, only the value of the
Flash.Result variable is returned to the Flash
application. Although you are limited to returning a single variable to the Flash application, that
variable can contain a single value, an array, a structure, or a record set returned from a
ColdFusion query.
For more information about converting data types between ColdFusion and Flash, see Chapter 4,
“Using Flash Remoting Data in ActionScript,” on page 63.
The following procedure creates the service function helloWorld, which returns a structure that
contains simple messages to the Flash application.
To create a ColdFusion page that returns a structure:
1.
Create a folder in a directory accessible to ColdFusion and your web server, and name it
helloExamples. This directory can go under your web root directory.
2.
Create a ColdFusion page, and save it as helloWorld.cfm in the helloExamples directory.
3.
Edit the helloWorld.cfm page to insert the following code:
<cfset tempStruct = StructNew()>
<cfset tempStruct.timeVar = DateFormat(Now ())>
<cfset tempStruct.helloMessage = "Hello World">
<cfset Flash.Result = tempStruct>
In the example, you add two string variables to a structure, one with a formatted date and one
with a simple message. The structure is returned to the Flash application using the
Flash.Result variable.
4.
Save the file.