User Guide

Table Of Contents
Handling function results in ActionScript 137
For more information, see the next section.
Handling function results in ActionScript
In Java application servers, you handle function results in ActionScript the same way that you do
for other platforms that Flash Remoting supports. You write an ActionScript result handler
function and tell the RelayResponder object its name. For example, to pass the return value of the
following ActionScript function to ActionScript:
function calculate()
{
loanService.calculate( (number (principalInput.text)), (number
(monthsInput.text)), (number (rateInput.text)) );
}
You would use the following ActionScript function:
function calculate_Result(re:mx.rpc.ResultEvent)
{
payOutput.text = re.result;
}
If a method returns an object that implements the Java Serializable interface, and all of its fields
are serializable, its public and private properties are available as ActionScript properties. For
example, the following method in a Java class called Loan calculates loan payments and returns an
instance of a JavaBean called
LoanInfo that stores values for the principal, months, rate, and
monthlyPayment properties:
public LoanInfo calculateReturnComplex(double principal, int months, float
rate){
if (rate < 0 || rate>1)
principal = 0.0;
double monthlyPayment = principal * (rate / (1 - Math.pow(1 +
rate,-months)));
LoanInfo info=new LoanInfo(principal, months, rate, monthlyPayment);
return info;
}
You could use the following calculate() function to call this method in ActionScript:
import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.Result.Event;
mx.remoting.debug.NetDebug.initialize();
//…
function calculate()
{
pc:PendingCall = loanService.calculateReturnComplex( (number
(principalInput.text)), (number (monthsInput.text)), (number
(rateInput.text)) );
pc.responder = new RelayResponder(this, "calculateReturnComplex_Result",
"calculateReturnComplex_Fault");
}