136
Chapter 7: Using Flash Remoting for Java
Getting a reference to a server-side ActionScript file
Before calling the functions of a server-side ActionScript file (with the .asr extension), 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.
Import the Flash Remoting files:
import mx.remoting.Service;
2.
Connect to the Flash Remoting gateway and get a reference to the server-side ActionScript file:
flashasService = new Service(
"http://localhost/flashservices/gateway"),
null,
"
flash.script.FlashSample
",
null,
null)
Note:
There are several other ways to specify the gateway URL. For more information, see
Chapter 2, “Using Flash Remoting ActionScript,” on page 29
.
The third parameter of the
Service
constructor 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 filename.
Invoking server-side ActionScript functions
After 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. Here,
flashssasService
represents
your reference to the server-side ActionScript file.
function getBiggerString()
{
pc:mx.remoting.PendingCall = flashsasService.getBiggerString(
stringInput.text );
pc.responder = new mx.rpc.RelayResponder(this, "getBiggerString_Result",
"getBiggerString_Fault");
}
To handle the function results, you use a result handler function like the following:
function getBiggerString_Result( re:mx.rpc.ResultEvent ):Void
{
stringOutput.text = re.result;
}
Содержание FLASH REMOTING MX
Страница 1: ...Using Flash Remoting for Flash MX 2004 ActionScript 2 0...
Страница 8: ...8 Contents...
Страница 62: ...62 Chapter 3 Using the RemotingConnector component Flash Professional only...
Страница 142: ...142 Chapter 7 Using Flash Remoting for Java...