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

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