O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

20.15. Receiving Typed Objects with ColdFusion

Problem

You want to be able to handle typed object parameters (i.e., properties of an object that store data of a custom type) sent to a ColdFusion back end (a CFC function or a CFM page).

Solution

Work with the parameter as an ASObject. Use the get( ) method to get the values for the properties, and use the getType( ) method to get the registered class name.

Discussion

Typed objects are automatically converted to ASObject datatypes in ColdFusion. ASObject is a Java class that extends the java.util.HashMap class (meaning all the properties and methods of a HashMap will also work for an ASObject) that also adds the getType( ) and setType( ) methods. If you are not yet familiar with how to work with Java objects in ColdFusion, you can read more about this in the ColdFusion documentation here:

http://livedocs.macromedia.com/cfmxdocs/Developing_ColdFusion_MX_Applications_with_CFML/Java5.jsp#1134356

Here is an example of a snippet of ActionScript code that creates a typed object and sends it to a ColdFusion service function:

function MyClass(a, b) {
  this.a = a;
  this.b = b;
}
MyClass.prototype.a;
MyClass.prototype.b;

Object.registerClass("MyClass", MyClass);

// Send a new MyClass object to a ColdFusion service function.
myCFService.serviceFunction(myResponseObj, {param: new MyClass("eh", "bee")});

Here is an example of a ColdFusion snippet that extracts the values from properties named a and b from an ASObject named param and also retrieves the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required