Building a Hello World application with Flash Remoting

In this section, you build a simple Flash application that uses Flash Remoting MX to connect to four different remote services, including a ColdFusion page, a JavaBean, an ASPX page, and a web service. You will see that Flash applications require minimal changes to call different remote services.

To build the Hello World application, see the following sections:

Building the remote service

Flash Remoting MX supports Java, ASP.NET, and ColdFusion-based remote services. For a simple Hello World application, the following table lists the application server code by platform and where to save the file to make it available to Flash Remoting MX:

Application Server

Application server code

File location
ColdFusion MX
<cfset flash.result = "Hello from ColdFusion MX!">
Save the ColdFusion page as helloWorld.cfm in a folder named remoteservices under your webroot.
JRun 4
package com.remoteservices;

import java.io.Serializable;

public class FlashJavaBean
  implements Serializable {

  private String message;

  public FlashJavaBean() {
    message = "Hello from Java!";
  }
  public String helloWorldJava() {
    return message;
  }

}
Save the compiled JavaBean class file to classes/com/remoteservices folder under the SERVER-INF directory.
ASP.NET
<%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %>
<%@ Page language="c#" debug="true" %>
<Macromedia:Flash ID="Flash" runat="server">
  Hello from .NET!
</Macromedia:Flash>
Save the ASPX page as helloWorldNET.aspx in the flashremoting directory under your webroot.

For more information about application server-specific documentation, see the following chapters:

Calling the remote service from ActionScript

To build a Flash application that uses Flash Remoting MX, you write ActionScript in the Flash MX authoring environment that connects to the remote service and calls a service function. For more information on building Flash applications that use Flash Remoting MX, see Chapter 2, "Using Flash Remoting Components in ActionScript".

To build the Flash application that calls remote services using Flash Remoting:

  1. In the Flash MX authoring environment, create a new Flash file, and save it as serviceTest.fla.
  2. In the document window, insert a text field and a PushButton UI component.
  3. Select the text field with your mouse. In the Properties Inspector, name the text field messageDisplay, and select Dynamic Text in the menu.
  4. Select the PushButton UI component with your mouse. In the Properties Inspector, enter button_Clicked in the Click Handler parameter, and enter "Anyone there?" in the Label parameter.
  5. Open the Actions Panel, and select Actions for Frame 1 of Layer 1 in the menu. Insert the following ActionScript code:
    //imports the NetServices ActionScript file
    #include "NetServices.as"
    //if statement creates the connection to the remote service and creates a service object
    if (inited == null)
    {
      inited = true;
      NetServices.setDefaultGatewayURL("gatewayURL");
      serviceConnection = NetServices.createGatewayConnection();
      serviceObject = serviceConnection.getService("serviceName", this);
    }
    //function executes when the user clicks the button
    function button_Clicked()
    {
      //service function call to the remote service
      serviceObject.serviceFunctionName();
    }
    //if the service function is successful, the _Result function of the same name executes
    function serviceFunctionName_Result(result)
    {
      messageDisplay.text = result;
    }
    //if the service function is unsucessful, the _Status function of the same name executes
    function serviceFunctionName_Status(result)
    {
      messageDisplay.text = error.description;
    }
    

    In the code, the ActionScript creates a reference to the remote service using the NetServices functions setDefaultGateway, createGatewayConnection, and getService. You specify the following variables:

  6. Save the file.

Using the previous ActionScript as a template, the following table lists the values for service name and service function variables:

Remote service
Service name
Service function name
ColdFusion MX
remoteservices
helloWorld
JRun 4
com.remoteservices
helloWorldJava
ASP.NET
remoteservices
helloWorldNET
Web service
http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl
getQuote

For more information about application server-specific service name and service function names, see the following chapters: