DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 20.11 Passing Named Parameters to ColdFusion Component Methods

20.11.1 Problem

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

20.11.2 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.

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

20.11.4 See Also

Recipe 20.12

    [ Team LiB ] Previous Section Next Section