20.11. Passing Named Parameters to ColdFusion Component Methods

Problem

You want to pass named parameters to a ColdFusion Component (CFC) method using Flash Remoting.

Solution

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.

Discussion

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 correspond to the names you have given to the parameters in the CFC method. ColdFusion automatically matches up the object’s property values to the CFC method’s parameters with the same names. For example:

<!--- 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);

See Also

Recipe 20.12

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.