AMF and Client-Side Serialization
AMF is crucial for all types of serialization and communications.
All native data serialization is customarily handled by the class ByteArray
. When serialized, the data type
information is marked out by the name included in the metadata tag
RemoteClass
.
Example 6-1 is a
small example from the Flash Builder’s NetworkingSamples project that comes with the
book. It includes an application RegisteredClassvsUnregistered.mxml and two
classes: RegisteredClass
and Unregistered
.
Example 6-1. Serialization with and without the RemoteObject meta tag
package { [RemoteClass(alias="com.RegisteredClass")] public classRegisteredClass
{ } } package { public classUnregisteredClass
{ } } <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="test()"> <mx:Script> <![CDATA[ import flash.utils.ByteArray private function serializeDeserialize(a:Object) : void { var ba : ByteArray = new ByteArray(); ba.writeObject(a); ba.position = 0; var aa:Object = ba.readObject(); trace( aa ); } private function test():void { serializeDeserialize( new RegisteredClass()); serializeDeserialize( new UnregisteredClass()); } ]]> </mx:Script> </mx:Application>
In Example 6-1, the
function serializeDeserialize()
serializes the object passed as an argument into a ByteArray
, and then reads it back into a
variable aa
of type Object
. The application makes two calls to this function. During the first call, it passes an object that contains ...
Get Agile Enterprise Application Development with Flex 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.