20.12. Passing Complex Parameters to ColdFusion Component Methods

Problem

You want to pass an object parameter to a ColdFusion Component (CFC) method using Flash Remoting.

Solution

Pass the value as a named parameter.

Discussion

ColdFusion automatically attempts to convert object parameters into named parameters (see Recipe 20.11). This is problematic if you want to pass an ActionScript object to a CFC method as a parameter. Consider the following example:

<!--- A sample CFC method definition --->
<cffunction name="insertCatalogItem" access="remote">
  <cfargument name="catalogItem" type="struct">
  <!--- rest of method body --->
<cffunction>

// The corresponding ActionScript snippet . . . 

// Create an item object with name, price, and description properties.
item = new Object(  );
item.name = "Widget";
item.price = 9.99;
item.description = "Widgets available in green, blue, and gold";

// Call the insertCatalogItem(  ) service function and pass it the item object.
myService.insertCatalogItem(myResponseObject, item);

In the preceding example, we want to pass the item object from Flash to the CFC method as a parameter that should be converted into a struct (a complex datatype). However, ColdFusion attempts to convert the properties of the item object into named parameters, and it tries to match up the name, price, and description properties to corresponding parameters within the CFC method. This prevents it from successfully passing a complex parameter, such as an object datatype.

You should ...

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.