Flash Remoting application structure

Using Flash Remoting MX to call an application service is similar to calling a web service or making a remote procedure call (RPC), because you make a call to some remote service and you get a response from the service. As with web services and RPCs, data from the remote service gets converted from the native data type of the remote service (such as a Java or C# data type) to a representation that is used to transfer the data over the network.

Unlike an RPC or web service request, a call made using Flash Remoting MX does not directly receive the results of the service. Instead, you write a result-handler callback routine to handle the returned data. Because the remote service call and callback routine are separate, your service call and result handling are asynchronous. In other words, the service request is like a function call without a return, and the service result response is like a Flash event, for which you write an event handler method. The following figure shows this relationship:

To interact with application servers using Macromedia Flash Remoting MX, do the following in your Flash application ActionScript:

  1. Include the Flash Remoting ActionScript files.
  2. Configure Flash Remoting MX.
  3. Call service functions and pass parameters.
  4. Handle the results and error status information returned to Flash in result event-handler routines.

The following example ActionScript code makes two Flash Remoting service calls, which get a temperature and a forecast. Each Flash Remoting service call has a corresponding result-handler callback method to show the results in the Flash application, and a status handler to handle any error information from Flash Remoting MX.

/* Include Flash Remoting ActionScript files. */

#include "NetServices.as"
// uncomment the next line to use the NetConnection debugger
// #include "NetDebug.as"

/* Configure Flash Remoting MX. */

if (inited == null)
{
  inited = true;
    NetServices.setDefaultGatewayURL("http://services.
      myco.com/  flashservices/gateway")
    gatewayConnection = NetServices.createGatewayConnection();
    weatherService = gatewayConnection.getService 
      ("flashExamples.weatherStation", this); 
      }

/* Call the service */

  weatherService.getTemperature("New York");
  weatherService.getForecast("Chicago");

/* 
 *Callback functions handle returned results 
 *and error status information from the service functions.
 */
function getTemperature_Result(temperature)
  temperatureIndicator.text = temperature; }
function getForecast_Result(forecast)
  forecastIndicator.text = forecast; }
function onStatus(errorinfo)
  {message.text = errorinfo.description; }

Although a more complex application would be structured differently, the preceding example shows the fundamental elements of a Flash Remoting MX application.

Note:   Flash Remoting MX applications must ensure that the r40 revision or later of the Macromedia Flash Player 6 is installed in the client browser. Use the Macromedia Flash deployment kit and the codebase tag to create the detection. The deployment kit is available at http://www.macromedia.com/software/flash/download/deployment_kit/, and includes instructions. For more information on ensuring that the correct version of Flash Player for Flash Remoting MX is installed on the client's system, see the Flash Remoting MX Support Center at http://www.macromedia.com/support/flash/flashremoting/.