User Guide

Table Of Contents
Calling Java classes or JavaBeans from ActionScript 123
Invoking Java methods in ActionScript
After you have created a reference to a Java class or JavaBean, you can use ActionScript functions
to invoke that object’s public methods. Consider the following JavaBean method:
public String getMessage() {
count++;
return message + " (count=" + count + ")";
}
You could use the following ActionScript code to invoke the getMessage() method, for example,
assuming
flashtestService represents your reference to the JavaBean:
function getMsg():Void
{
var pc:PendingCall = flashtestService.getMessage();
pc.responder = new RelayResponder( this, "getMessage_Result",
"getMessage_Fault");
}
The second line creates a RelayResponder and assigns it to the responder property of the pc
PendingCall object. The RelayResponder identifies the methods that handle the result and fault
conditions. The first parameter,
this, specifies that the results of the service function call are
returned to those methods in this object. If the result handling methods were contained in a
different object, you would specify the name of that object.
To handle the function results, you use a result handler function and a fault handler function like
the following:
function getMessage_Result( re:ResultEvent ):Void
{
messageOutput.text = re.result;
}
function getMessage_Fault( fe:FaultEvent ):Void
{
mx.remoting.debug.NetDebug.trace({level:"None", message:"There was a
problem" + fe.fault.faultstring});
}
For more information, see “Handling function results in ActionScript” on page 137.
Looking at a Flash application that calls a JavaBean
The following sections examine the three parts of an application that are required to call a
JavaBean from a Flash application that uses Flash Remoting:
“Looking at the JavaBean code” on page 124
“Looking at the user interface for the JavaBean” on page 125
“Looking at the ActionScript code that calls the JavaBean” on page 125