20.17. Receiving Typed Objects with Java

Problem

You want to handle typed objects using a J2EE service function.

Solution

Use JavaBean classes that correspond to the ActionScript classes, and use the third-party ASTranslator class to perform conversions between datatypes.

Discussion

Unlike the .NET version, Flash Remoting for J2EE does not automatically convert typed ActionScript objects into corresponding custom Java types. Instead, the gateway converts the ActionScript objects into ASObject types. The flashgateway.io.ASObject class (included in flashgateway.jar) is a subclass of java.util.HashMap to which two additional methods (getType( ) and setType( )) have been added. The properties of the ActionScript object are stored as key/value pairs in the ASObject. You can create your own proprietary code to convert between an ASObject and the appropriate Java datatype. However, Carbon Five has already created an excellent utility named ASTranslator to do this for you.

ASTranslator is freely available for download from http://www.carbonfive.com/opensource-main-1.html. It converts between ASObject and custom Java datatypes using JavaBean-style introspection. Therefore, it requires that your custom Java datatypes adhere to the JavaBean rules (namely, they must implement java.io.Serializable, use get/set methods for all publicly accessible properties, and have a constructor that requires no parameters).

Here is how to use ASTranslator to receive typed objects and convert them to custom Java ...

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.