User Guide

Table Of Contents
Building a simple application 833
Building a simple application
The following procedure describes how to build a simple server-side ActionScript application.
The example application, a corporate personnel directory, uses the NetServices object to connect
to the
personneldirectory server-side ActionScript. The personneldirectory server-side
ActionScript retrieves data from a ColdFusion MX data source and returns the results to the Flash
application as a RecordSet object.
Note: The server-side ActionScript application that you create provides the back-end services in an
application.
This example requires the following:
A server-side ActionScript file named personneldirectory.asr that includes functions that
interact with a ColdFusion MX data source.
A client-side Flash MX movie in which the NetServices object is created.
To create the application:
1.
Write server-side ActionScript that performs the database query and returns data to the client
through the Flash Remoting service.
2.
Create the Flash movie interface. See “Creating the Flash movie interface” on page 834.
3.
Define a search function that sends user data to the Flash Remoting service. See “Submitting
user data to the Flash Remoting service” on page 834.
4.
Define a result function that captures the results returned from the Flash Remoting service. See
“” on page 835.
5.
Ensure that the Flash movie has established a connection to the Flash Remoting service. See
“Checking for a Flash Remoting service connection” on page 836.
Writing the server-side ActionScript function
The example in this section creates a search function that performs a simple search operation
against a ColdFusion MX data source. This function accepts two arguments, firstName and
lastName, and returns any records found that match these arguments.
To create a server-side ActionScript function:
1.
Create a server-side ActionScript file that contains the following code:
//search takes firstName lastName arguments
function search(firstName, lastName)
{
searchdata = CF.query({datasource: "bigDSN",
sql:"SELECT * from personnel WHERE fname = firstName AND lname =
lastName"{);
if (searchdata)
return searchdata;
else
return null;
}
2.
Save the file as personneldirectory.asr.