View comments | RSS feed

Calling server-side ActionScript from Flash (JRun only)

This section describes how to call a server-side ActionScript file from Flash using Flash Remoting MX. The ability to create server-side ActionScript provides a familiar way for Flash developers to create server-side code without learning Java. You can also call server-side Java objects from server-side ActionScript. JRun uses the Mozilla Rhino JavaScript engine to support server-side ActionScript; for more information about calling Java objects with Rhino, go to http://www.mozilla.org/rhino/scriptjava.html.

Getting a reference to a server-side ActionScript file

Before calling the functions of a server-side ActionScript file (*.asr), you must get a reference to the file. Place the server-side ActionScript file that you want to call in a web application.

To get a reference to a server-side ActionScript file:

  1. Include the NetServices.as file:
    #include "NetServices.as"
    
  2. Specify the default Flash Remoting gateway URL:
    NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway"); 
    

    Note:   There are several other ways to specify the gateway URL. For more information, see Chapter 2, "Using Flash Remoting Components in ActionScript".

  3. Connect to the Flash Remoting gateway:
    gatewayConnection = NetServices.createGatewayConnection();
    
  4. Get a reference to the server-side ActionScript file, as shown in the following example:
    flashsasService = gatewayConnection.getService (flash.script.FlashSample", this);
    

    The first parameter of the getService function is the directory structure and name of the ASR file relative to a web application context root. In this example, flash is the context root of the web application, script is a directory under the context root, and FlashSample is the prefix of the ASR file name. The second parameter of the getService function, this, specifies that the result of service function calls are returned to this Flash timeline.

Invoking server-side ActionScript functions

Once you have a reference to a server-side ActionScript file, you can use client-side ActionScript functions to call its functions. For example, to call the following server-side ActionScript function:

function getBiggerString(value)
{
    return "Hello from SSAS " + value;
}

You could use the following client-side ActionScript code, assuming flashssasService represents your reference to the server-side ActionScript file:

function getBiggerString()
{
  flashssasService.getBiggerString( stringInput.text );
  //wait for the results
  stringOutput.text = "[Invoking SSAS...]";
}

To handle the function results, you use a result handler function like the following:

function getBiggerString_Result( result )
{
  stringOutput.text = result;
}

For more information about handling function results in ActionScript, see "Handling function results in ActionScript".

Comments


No screen name said on Aug 2, 2005 at 9:08 PM :
It is really helpful about Flash Remoting. But not much detail.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/usingFRJ2EE7.htm