Recipe 20.10 Calling ColdFusion Functions from Flash
You want to invoke ColdFusion service functions using Flash Remoting.
Preferably use a ColdFusion Component (CFC). Alternatively, you can invoke a ColdFusion page, with some modifications.
When you are using ColdFusion, there are two types of Flash Remoting service functions: ColdFusion pages and CFC
Preferably, you should use CFC methods instead of ColdFusion pages for all of your Flash Remoting needs. Calling a CFC method from Flash Remoting does not require any special code changes to the CFC. The only consideration is that you must make sure that the CFC method can be accessed remotely by setting the
attribute to "remote", as
<cffunction name="myCFCMethod" access="remote"> <!--- method body ---> </cffunction>
When you want to call a CFC method from a Flash movie, you should create a service object that maps to the CFC by specifying the fully qualified CFC name in the getService( ) method. The fully qualified CFC name includes any packages in which the CFC has been placed. For example:
// Create a service object that maps to a CFC named MyCFC in the root of the // ColdFusion application. myService = myConnection.getService("MyCFC"); // Or, if the CFC is in a package, create a service object including the package // name. This example maps to a CFC named MyCFC in the OReilly.ASCB package. myService = myConnection.getService("OReilly.ASCB.MyCFC");
If you must use a ColdFusion page with Flash Remoting, you must make changes to the code within the page. Any values that the page receives or returns are contained within the ColdFusion
scope. All parameters that you send to the ColdFusion page via the service function invocation are stored in the
array within the
scope. If you want to return a value to the Flash movie from the ColdFusion page, you should assign that value to the
variable within the
scope. You can return only one value per ColdFusion page. The last value assigned to the
variable when the page has been
<!--- Set two variables within the ColdFusion page to the values of the first two parameters passed to the page from the Flash movie that called it ---> <CFSET myFirstParam = FLASH.params> <CFSET mySecondParam = FLASH.params> <!--- Return a value to the Flash movie ---> <CFSET FLASH.result = "a return value">
20.10.4 See Also
Recipe 20.11 Passing Named Parameters to ColdFusion Component Methods
You want to pass named parameters to a ColdFusion Component (CFC) method using Flash Remoting.
Create an ActionScript object with properties corresponding to the expected CFC method parameters, and pass that object as a single parameter to the CFC method.
You can pass named parameters (as opposed to positional parameters) to a CFC method from a Flash movie. To accomplish this, you should pass a single object parameter to the CFC method in which the property names
<!--- A sample CFC method definition ---> <cffunction name="getCarInfo" access="remote"> <cfargument name="make" type="string"> <cfargument name="model" type="string"> <!--- rest of method body ---> <cffunction> // The corresponding ActionScript snippet . . . // Create an object with properties named make and model . params = new Object( ); params.make = "Honda"; params.model = "Accord"; // Call the getCarInfo( ) service function and pass it the params object. myService.getCarInfo(myResponseObject, params);
20.11.4 See Also
ActionScript 3.0 Bible
The ActionScript 3.0 Quick Reference Guide: For Developers and Designers Using Flash: For Developers and Designers Using Flash CS4 Professional (Adobe Developer Library)
Essential ActionScript 3.0 (Essential)
ActionScript 3.0 Design Patterns: Object Oriented Programming Techniques (Adobe Developer Library)