ColdFusion 9.0 Resources |
Using the Flash Remoting service with ColdFusion pagesWhen you build a ColdFusion page that interacts with a SWF application, the directory name that contains the ColdFusion pages translates to the service name that you call in ActionScript. The individual ColdFusion page names within that directory translate to service functions that you call in ActionScript. Note: Flash Remoting cannot interact with virtual
directories accessed through a ColdFusion mapping.
In your ColdFusion pages, you use the Flash variable scope to access parameters passed to and from a SWF application. To access parameters passed from a SWF application, you use the parameter name appended to the Flash scope or the Flash.Params array. To return values to the SWF application, use the Flash.Result variable. To set an increment value for records in a query object to be returned to the SWF application, use theFlash.Pagesize variable. The following table shows the variables contained in the Flash scope:
The following table compares the ColdFusion data types and their ActionScript equivalents:
Also, remember the following considerations regarding data types:
For a complete explanation of using Flash Remoting data in ActionScript, see Using Flash Remoting MX 2004Help. Accessing parameters passed from FlashTo access variables passed from SWF applications, you append the parameter name to the Flash scope or use the Flash.Params array. Depending on how the values were passed from Flash, you refer to array values using ordered array syntax or structure name syntax. Only ActionScript objects can pass named parameters. For example, if you pass the parameters as an ordered array from Flash,array[1] references the first value. If you pass the parameters as named parameters, you use standard structure-name syntax like params.name. You can use most of the CFML array and structure functions on ActionScript collections. However, the StructCopy CFML function does not work with ActionScript collections. The following table lists ActionScript collections and describes how to access them in ColdFusion:
The Flash.Params array retains the order of the parameters as they were passed to the method. You use standard structure name syntax to reference the parameters; for example: <cfquery name="flashQuery" datasource="cfdocexamples"> SELECT ItemName, ItemDescription, ItemCost FROM tblItems WHERE ItemName EQ '#Flash.paramName#' </cfquery> In this example, the query results are filtered by the value of Flash.paramName, whichreferences the first parameter in the passed array. If the parameters are passed as an ordered array from the SWF application, you use standard structure name syntax; for example: <cfset Flash.Result = "Variable 1:#Flash.Params[1]#, Variable 2: #Flash.Params[2]#"> Note: ActionScript array indexes start at zero. ColdFusion
array indexes start at one.
Returning results to FlashIn ColdFusion pages, only the value of the Flash.Result variable is returned to the SWF application. For more information about supported data types between ColdFusion and Flash, see the data type table in Using the Flash Remoting service with ColdFusion pages. The following procedure creates the service function helloWorld, which returns a structure that contains simple messages to the SWF application. Create a ColdFusion page that passes a structure to a SWF application
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 FlashColdFusion 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
When you assign a value to the Flash.Pagesize variable, you are specifying that if the record set has more than a certain number of records, the record set becomes pageable and returns the number of records specified in the Flash.Pagesize variable. For example, the following code calls the getData() function of the CFMService and uses the first parameter to request a page size of 5: import mx.remoting.*; import mx.services.Log; import mx.rpc.*; // Connect to helloExamples service and create the CFMService service object var CFMService:Service = new Service( "http://localhost/flashservices/gateway", null, "helloExamples", null, null ); // Call the service getData() method var pc:PendingCall = CFMService.getData(5); // Tell the service what methods handle result and fault conditions pc.responder = new RelayResponder( this, "getData_Result", "getData_Fault" ); function getData_Result(re:ResultEvent) { // Display successful result DataGlue.bindFormatStrings(employeeData, re.result, "#PARKNAME#, #CITY#, #STATE#"); } function getData_Fault(fe:FaultEvent) { // Display fault returned from service trace("Error description from server: " + fe.fault.description); } In this example, employeeData is a Flash list box. The result handler, getData_Result, displays the columns PARKNAME, CITY, and STATE in the employeeData list box. After the initial delivery of records, the RecordSet ActionScript class assumes the task of fetching records. In this case, the list box requests more records as the user scrolls the list box. You can configure the client-side RecordSet object to fetch records in various ways using the RecordSet.setDeliveryMode ActionScript function. |