User Guide

Table Of Contents
818 Chapter 33: Using the Flash Remoting Service
The following example replicates the helloWorld function that was previously implemented as a
ColdFusion page. For more information, see “Using the Flash Remoting service with ColdFusion
pages” on page 812.
To create a CFC that interacts with a Flash application:
1.
Create a CFC and save it as flashComponent.cfc in the helloExamples directory.
2.
Modify the code in flashComponent.cfc so that it appears as follows:
<cfcomponent name="flashComponent">
<cffunction name="helloWorld" access="remote" returnType="Struct">
<cfset tempStruct = StructNew()>
<cfset tempStruct.timeVar = DateFormat(Now ())>
<cfset tempStruct.helloMessage = "Hello World">
<cfreturn tempStruct>
</cffunction>
</cfcomponent>
In this example, the helloWorld function is created. The cfreturn tag returns the result to
the Flash application.
3.
Save the file.
The
helloWorld service function is now available through the flashComponent service to
ActionScript. The following ActionScript example calls this function:
import mx.remoting.*;
import mx.services.Log;
import mx.rpc.*;
// Connect to the Flash component service and create service object
var CFCService:Service = new Service(
"http://localhost/flashservices/gateway",
null,
"helloExamples.flashComponent",
null,
null );
// Call the service helloWorld() method
var pc:PendingCall = CFCService.helloWorld();
// Tell the service what methods handle result and fault conditions
pc.responder = new RelayResponder( this, "helloWorld_Result",
"helloWorld_Fault" );
function helloWorld_Result(re:ResultEvent)
{
// Display successful result
messageDisplay.text = re.result.HELLOMESSAGE;
timeDisplay.text = re.result.TIMEVAR;
}
function helloWorld_Fault(fe:FaultEvent)
{
// Display fault returned from service
messageDisplay.text = fe.fault;
}