
618
DEVELOPING
COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
Las
t
upda
te
d 8/5/2010
package utils;
public class UIComponents
{
public UIComponents()
{
}
public String sayHello()
{
return "Hello";
}
}
Note:
You cannot call constructors with Flash Remoting. Use the default constructor.
In ActionScript, the following
javaService
call runs the
sayHello
public method of the
utils.UIComponents
class:
import mx.remoting.*;
import mx.services.Log;
import mx.rpc.*;
// Connect to service and create service object
var javaService:Service = new Service(
"http://localhost/flashservices/gateway",
null,
utils.UIComponents",
null,
null );
// Call the service sayHello() method
var pc:PendingCall = javaService.sayHello();
// Tell the service what methods handle result and fault conditions
pc.responder = new RelayResponder( this, "sayHello_Result", "sayHello_Fault" );
function sayHello_Result(re:ResultEvent)
{
// Display successful result
trace("Result is: " + re.result);
}
function sayHello_Fault(fe:FaultEvent)
{
// Display fault returned from service
trace("Error is: " + fe.fault.description);
}
Note:
For more information about using Java objects with ColdFusion, see “
Using Java objects
” on page
1135
Handling errors with ColdFusion and Flash
To help with debugging, use
cftry
and
cfcatch
tags in your ColdFusion page or component to return error messages
to Flash Player. For example, the ColdFusion page, causeError.cfm, contains the code:
<cftry>
<cfset dev = Val(0)>
<cfset Flash.Result = (1 / dev)>
<cfcatch type = "any">
<cfthrow message = "An error occurred in this service: #cfcatch.message#">
</cfcatch>
</cftry>