Using RemoteObject components

Using RemoteObject components

http://help.adobe.com/en_US/Flex/4.0/AccessingData/WS2db454920e96a9e51e63e3d11c0bf69084-7fda.html

http://stackoverflow.com/questions/1671668/how-does-remoteclass-work-in-flex-actionscript-can-i-use-it-for-custom-data-bi 

[RemoteClass(alias="com.example.MyClass")] is a Flex shorthand for calling flash.net.registerClassAlias() :

public function registerClassAlias(aliasName:String, classObject:Class):void
To access those registered alias classes at runtime (to write a custom JSON data serialization framework) you can call:

getClassByAlias(aliasName:String):Class Looks up a class that previously had an alias registered through a call to the registerClassAlias() method.

For outgoing encoding from AS to Java you need to retrieve the aliased class name, you can do that by calling flash.utils.describeType() and use "reflection" on your Actionscript object's class to query attributes, properties, methods of the object.

For example the following code snippet for ObjectCodec.as seems to retrieve the alias attribute by using "@":

override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void
{
                var desc:XML = describeType(o);
                var classAlias:String = desc.@alias;
                //...
}

[RemoteClass] is only used on the Flex side. All it really does is call the flash.net.registerClassAlias() function to setup a mapping between a local object and a remote class name.

 

 

posted @ 2011-12-09 10:54  Stranger  阅读(182)  评论(0编辑  收藏  举报