
614
DEVELOPING
COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
Las
t
upda
te
d 8/5/2010
2
Create a ColdFusion page, and save it as helloWorld.cfm in the helloExamples directory.
3
Modify helloWorld.cfm so that the CFML code appears as follows:
<cfset tempStruct = StructNew()>
<cfset tempStruct.timeVar = DateFormat(Now ())>
<cfset tempStruct.helloMessage = "Hello World">
In the example, two string variables are added to a structure; one with a formatted date and one with a simple
message. The structure is passed back to the SWF application using the
Flash.Result
variable.
<cfset Flash.Result = tempStruct>
4
Save the file.
Remember, the directory name is the service address. The helloWorld.cfm file is a method of the
helloExamples
Flash
Remoting service. The following ActionScript example calls the helloWorld ColdFusion page and displays the values
that it returns:
import mx.remoting.*;
import mx.services.Log;
import mx.rpc.*;
// Connect to helloExamples service and create the howdyService service object
var howdyService:Service = new Service(
"http://localhost/flashservices/gateway",
null,
"helloExamples",
null,
null );
// Call the service helloWorld() method
var pc:PendingCall = howdyService.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;
}
Note:
Due to ActionScript's automatic type conversion, do not return a Boolean literal to Flash from ColdFusion. Return
1
to indicate
true
, and return
0
to indicate
false
.
Returning records in increments to Flash
ColdFusion lets you return record set results to Flash in increments. For example, if a query returns 20 records, you
can set the
Flash.Pagesize
variable to return five records at a time to Flash. Incremental record sets let you minimize
the time that a SWF application waits for the application server data to load.
Create a ColdFusion page that returns an incremental record set to Flash
1
Create a ColdFusion page, and save it as getData.cfm in the helloExamples directory.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...