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.14. Transmitting Custom Datatypes to a Flash Remoting Back End

Problem

You want to create an object of a custom type to send to a Flash Remoting back end.

Solution

On the client-side, create a custom class in the ActionScript code, and then use Object.registerClass( ) to register it.

Discussion

Flash Remoting enables you to send and receive many different kinds of data—even custom datatypes—to and from a Flash Remoting back end. However, Flash has to know about the datatype for it to be properly transmitted. The Object.registerClass( ) method takes care of registering custom classes with the Flash movie so that it knows how to handle objects of those types when sending and receiving them via Flash Remoting. When you use the registerClass( ) method for this purpose, the first parameter should be an arbitrary name by which Flash should know the datatype, and the second parameter should be a reference to the class that you want to register. Conventionally, the name to which you register the class should match the class name.

// Create a custom class.
function MyClass(  ){}

// Register the class so that Flash knows it by the ID MyClass.
Object.registerClass("MyClass", MyClass);

Note that for the properties of a custom class to be correctly interpreted by Flash, when using this technique, you must declare the properties as members of the class’s prototype:

// Create a custom class. The constructor accepts two parameters and sets two // properties. Normally this would be all that is necessary. ...

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