
691
DEVELOPING
COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
Las
t
upda
te
d 8/5/2010
Coding the ColdFusion query and HTTP operations in ActionScript is very straightforward. The
CF.query
and
CF.http
functions provide a well-defined interface for building SQL queries and HTTP operations.
For example, the following is a typical server-side ActionScript function definition that returns query data:
// This function shows a basic CF.query operation using only
// arguments for data source name and for SQL.
function basicQuery()
{
mydata = CF.query({datasource:"customers",
sql:"SELECT * FROM myTable"});
return mydata;
}
What to do next
If you are already familiar with ActionScript, here a few things to get you started:
•
How to establish a connection with the Flash Remoting service using client-side ActionScript. See “
Connecting to
the Flash Remoting service
” on page 691
•
How to reference server-side ActionScript functions and methods. See “
Using server-side ActionScript functions
”
on page 692.
•
How to code the server-side
CF.query
and
CF.http
functions. See “
Using the CF.query function
” on page 694 and
“
Using the CF.http function
” on page 700. Also see the reference pages for these functions in the
CFML Reference
.
For additional information on using Flash Remoting, see “
Using the Flash Remoting Service
” on page 606 and
Using
Flash Remoting.
Connecting to the Flash Remoting service
Before you can use functions defined in your server-side ActionScript files, connect the Adobe SWF movie to the
server-side Flash Remoting service.
Create a Flash Remoting service connection
1
Include the necessary ActionScript classes in the first frame of the SWF movie that uses server-side ActionScript
functions.
a
Use the following command to include the
NetServices
class:
#include "NetServices.as"
b
(Optional) Use the following command to include the
NetDebug
class:
#include "NetDebug.as"
For more information about the
NetDebug
and
RecordSet
classes, see
Using Flash Remoting
.
2
Since the Flash Remoting service serves as a broker for calls to server-side ActionScript functions, identify the Flash
Remoting service URL as an argument in the
NetServices.setDefaultGatewayUrl
function. For example:
NetServices.setDefaultGatewayURL("http://localhost:8500/flashservices")
Specify a server host name. The default port number for the Flash Remoting service is 8500.
3
Create the gateway connection using the
NetServices.createGatewayConnection
function; for example:
gatewayConnection = NetServices.createGatewayConnection();