116
Chapter 6: Using Flash Remoting with ColdFusion MX
To handle the results of the web service method, you create an event handler with the same name
as the service functions with
_Result
or
_Fault
appended to the name. The result handler
displays the results in the
myGrid
DataGrid component, as the following example shows:
function getCategories_Result(result:ResultEvent):Void {
// display successful result
myGrid.dataProvider = result.result;
}
function getCategories_Fault(fault:FaultEvent):Void {
message_txt.text = fault.fault.description;
}
In this example, the result of the web service function call, represented by the
result.result
property, is assigned to the
dataProvider
property of the DataGrid component,
myGrid
, which
appears in the Flash application.
Securing access to ColdFusion from Flash Remoting
You can use the ColdFusion security mechanism to control access to ColdFusion files from Flash,
just as you control access to any ColdFusion page. In this way, you can grant Flash applications
access to only selected ColdFusion code.
ColdFusion security is based on a username and password. Flash Remoting applications can pass
the user name and password information using the
setCredentials()
function in ActionScript.
From within your ColdFusion Application.cfm page, you can use the
cflogin
tag to access this
information.
The following example passes a user name and password to ColdFusion:
import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
//…
var myService:Service = new Service(
"http://localhost/flashservices/gateway",
null,
"securityTest.thecfc",
null,
null);
myService.connection.setCredentials("myUserid", "myPassword");
Note:
Typically, you do not hard-code a user name and password within a Flash application, because
SWF files can be easily decompiled.
You use the
cflogin
tag to retrieve the user name and password information, as the following
example Application.cfm file shows:
<cfsilent>
<cflogin>
<cfif isDefined("cflogin")