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

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