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.
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.
#include "NetServices.as"
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".
gatewayConnection = NetServices.createGatewayConnection();
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.
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".
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
Comments
No screen name said on Aug 2, 2005 at 9:08 PM :