When building a ColdFusion page that interacts with Flash movies, the directory name that contains the ColdFusion pages translates to the Flash service name in ActionScript. The individual ColdFusion page names contained in that directory translate to service functions in ActionScript.
In your CFML, you use the Flash variable scope to access parameters passed from Flash movies and return values to Flash movies. To access parameters passed from Flash movies, you use the parameter name appended to the Flash
variable or the Flash.Params
array. To return values to the Flash application, use the Flash.Result
variable. To set an increment value for records to be returned to the Flash application, use the Flash.Pagesize
variable.
The following table shows the variables contained in the Flash scope:
In addition, the following table compares the ColdFusion data types and their ActionScript equivalents:
To access variables passed from Flash movies, 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 describes the collections and examples:
The Flash.Params
array retains the order of the parameters as they were passed to the function. You use standard structure name syntax to reference the parameters; for example:
<cfquery name="flashQuery" datasource="exampleapps" dbtype="ODBC">
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
, which
references the first parameter in the array. If the parameters were passed as an ordered array from Flash, you use standard structure name syntax; for example:
<cfset flash.result = "Variable 1:#Flash.params[1]#, Variable 2: #Flash.params[2]#">
In this ActionScript example, notice that ActionScript starts the array index at zero. ColdFusion array indexes start at one.
In ColdFusion pages, only the value of Flash.Result
variable is returned to the Flash 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 containing simple messages to the Flash application.
<cfset tempStruct = StructNew()> <cfset tempStruct.timeVar = DateFormat(Now ())> <cfset tempStruct.helloMessage = "Hello World">
Flash.Result
variable.
Remember, the directory name is used the service address, and the helloWorld.cfm file is a method of the helloExamples
Flash Remoting service. The following ActionScript example calls the helloWorld ColdFusion page:
include "NetServices.as"
NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway"); gatewayConnection = NetServices.createGatewayConnection(); CFMService = gatewayConnection.getService("helloExamples", this); CFMService.helloWorld();
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.
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 lets you minimize the time that Flash application waits for the application server data to load.
<cfparam name="pagesize" default="10"> <cfif IsDefined("Flash.Params")> <cfset pagesize = Flash.Params[1]> </cfif> <cfquery name="myQuery" datasource="ExampleApps"> SELECT * FROM tblParks </cfquery> <cfset Flash.Pagesize = pagesize> <cfset Flash.Result = myQuery>
In this example, if a single parameter is passed from the Flash application, the pagesize
variable is set to the value of the Flash.Params[1]
variable, otherwise the default is set to 10
. Next, a cfquery
statement queries the database. After that, the pagesize
variable is assigned into the Flash.Pagesize
variable. Finally, the query results are assigned into the Flash.Result
variable, which is returned 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
. For example:
include "NetServices.as"
NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway"); gatewayConnection = NetServices.createGatewayConnection(); CFMService = gatewayConnection.getService("helloExamples", this); CFMService.getData();
After the initial delivery of records, the RecordSet ActionScript class becomes responsible for fetching records. You can configure the client-side RecordSet object to fetch records in various ways using the setDeliveryMode
ActionScript function.