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 theflashgateway.io.ASObjectclass. Add thenameattribute with the arbitrary nameASObjectClassso that you can initialize the object properly. ---> <cfobject type="Java" class="flashgateway.io.ASObject" name="ASObjectClass" action="create" > <!--- Theinit( )method returns a properASObject. ---> <cfset aso = ASObjectClass.init( )> <!--- Set the type of theASObjectto 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access