About server-side ActionScript

Macromedia ColdFusion MX includes a module called the Macromedia Flash Remoting service that acts as a broker for interactions between Macromedia Flash MX and ColdFusion MX. In addition to support for a range of object types, Flash Remoting also lets you reference an ActionScript file that lives on a ColdFusion server.

The ability to create server-side ActionScript provides a familiar way for Flash developers to access ColdFusion resources without having to learn CFML (ColdFusion Markup Language). One benefit of this feature is that it lets you partition data-intensive operations on the server, while limiting the amount of network transactions necessary to get data from server to client.

In addition, this feature lets you logically separate the Flash presentation elements of your applications from the business logic. Now you have the option of creating ActionScript files that reside on the server to partition this processing away from your client applications.

You have a very simple interface for building queries using server-side ActionScript, and an equally simple interface for invoking these queries from your client-side ActionScript.

Client-side ActionScript requirements

On the client side, you only need a small piece of code that establishes a connection to the Flash Remoting service and references the server-side ActionScript you want to use.

For example (note embedded comments):

// This #include is needed to connect to the Flash Remoting service
#include "NetServices.as"

// This line determines where Flash MX should look for the Flash Remoting service.
// Ordinarily, you enter the URL to your ColdFusion server.
// Port 8100 is the Flash Remoting service default.
NetServices.setDefaultGatewayUrl("http://mycfserver:8100");

// With the Flash Remoting service URL defined, now you can create a connection.
gatewayConnnection = NetServices.createGatewayConnection();

// Here's where you reference the server-side ActionScript.
// In this case the stockquotes script file lives in the web root of the 
// ColdFusion server identified previously. If it lived in a subdirectory
// of the web root called "mydir," you would reference it 
// as "mydir.stockquotes".
stockService = gatewayConnnection.getService("stockquotes", this);

// This line invokes the getQuotes() method defined in the stockquotes
// server-side ActionScript.
stockService.getQuotes("macr");

// Once the record set is returned, you handle the results.
// This part is up to you.
function getQuotes_Result ( result )
{ 
  // Do something with results
}

Note:   The two new server-side ActionScript functions, CF.query and CF.http, are not supported in client-side ActionScript.

Server-side requirements

The option of creating ActionScript that executes on the server helps leverage your knowledge of ActionScript, while providing direct access to ColdFusion query and HTTP features. The CF.query and CF.http ActionScript functions let you perform ColdFusion HTTP and query operations:.

Note:   On the server side, ActionScript files use the extension .asr.

For example, the following server-side ActionScript builds on the client-side code shown previously:

// Filename: stockquotes.asr
// Here is the getQuotes method invoked in the client-side ActionScript.
// It accepts a single stock quote symbol argument.
function getQuotes(symbol)
{
  // Query some provider for the specified stock quote and return the 
  // results. In this case, the getQuotesFromProvider method is 
  // defined elsewhere in this ActionScript.
  data = getQuotesFromProvider(symbol);
  // Now return the data to the client.
  // Note that this example does not include any of the error checking
  // logic you would normally use prior to returning the data. 
  return data;
}

The getQuotes function conducts the stock quote request and returns the results of the request to the client as a RecordSet object.

Software requirements

To use server-side ActionScripts, you must have the following software installed:

For more information about these products, go to www.macromedia.com.

Comments