20.18. Returning Typed Objects from ColdFusion

Problem

You want to return a typed object from ColdFusion to a Flash movie.

Solution

Create an ASObject and set the type to match the name of a registered ActionScript class.

Discussion

When an ASObject is returned to a Flash movie, Flash attempts to find a registered class in which the registered name matches the name of the type that has been set for the ASObject via the setType( ) method. You can create an ASObject within ColdFusion using the ColdFusion techniques for creating Java objects. If you are not familiar with how to do this, you can read more about it in the ColdFusion documentation available here:

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

Here is an example of a ColdFusion Component method that creates and returns an ASObject:

<cffunction name="getTypedObject" access="remote">

  <!--- Create a Java object from the flashgateway.io.ASObject class. 
        Add the name attribute with the arbitrary name ASObjectClass so 
        that you can initialize the object properly. --->
  <cfobject type="Java" class="flashgateway.io.ASObject" 
            name="ASObjectClass" 
            action="create" >

  <!---  The init(  ) method returns a proper ASObject. --->
  <cfset aso = ASObjectClass.init(  )>

  <!--- Set the type of the ASObject to match the name 
        of a registered ActionScript class --->
  <cfset aso.setType("MyClass")>
  <cfset aso.put("a", "eh")>
  <cfset aso.put("b", "bee")>
  <cfreturn aso>
</cffunction>

Here is an example ...

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.