flexAMF3中序列化跟反序列化的Alias机制
flexAMF3中序列化和反序列化的Alias机制
很多人翻译Alias为“别名”,不太好,在金山词霸中还有另外一个意思“双面女间谍”,很形象。环境:服务器端使用java,客户端使用as3。
1)声明我的as3对象A是可以被强制转换为服务器端的java对象B的
在对象中使用
[RemoteClass(alias="B")]
public class A{ .... }
另外一种,在application中,module或者调用远程RemoteObject前使用:
registerClassAlias("B", A)
注:据网上资料说第一种使用元数据标签的内部实现是第二种。
2)怎么知道一个类是否有“别名”。使用方法:
一种方法getClassByAlias(aliasName:String):Class
二种方法,使用反射:
override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void { var desc:XML = describeType(o); var classAlias:String = desc.@alias; //... }
3)使用“别名”解决序列化时碰到的不能转换的错误。
要是有本《actionscript编程思想》就好了