我使用Cirrus將某些值傳遞給我的遊戲中的其他玩家,其中一些值是對象,事情是,當我收到這些對象時,它們丟失了類型,然後它們變爲通用對象。反序列化使用Cirrus接收的對象
我讀過Cirrus使用AMF,但我不知道如何恢復原始對象類型的數據。
編輯:
//these are the classes involved
registerClassAlias("Action", Action);
registerClassAlias("EntityVO", EntityVO);
registerClassAlias("Point", Point);
//Action takes 3 parameters
Action(type:String = "", entity:EntityVO = null, target:EntityVO = null)
// when EntityVO doesnt require a parameter in the constructor or it has a string/int parameter this works:
var entity = new EntityVO();
var byteArray:ByteArray;
byteArray = new ByteArray();
byteArray.writeObject(action);
byteArray.position = 0;
var object:Object = byteArray.readObject(); //<- works ok
//when I make EntityVO to take a non standard parameter like, a Point, like this:
EntityVO(point:Point = null)
//and I do this:
var entity:EntityVO = new EntityVO(new Point());
var action:Action = new Action("addEntity", entity);
var byteArray:ByteArray;
byteArray = new ByteArray();
byteArray.writeObject(action);
byteArray.position = 0;
var object:Object = byteArray.readObject(); //<- it goes into the EntityVO constructor and says that point is null, (I use point in the constructor to set something)
如果兩個swfs都具有相同版本的同一類,我會對此圖像進行自動反序列化,但我能想到的唯一問題是對象是否與交互客戶機上的版本不同。使用AMF與BlazeDS一起使用RemoteAlias元數據標記或註冊別名,但我相信這只是一個Java類名或PHP類名映射到AS3類,我會想象,因爲這是所有類型的AS3/AMF保留。你確定兩個客戶有相同的確切瑞士法郎嗎? – shaunhusain
是的,他們是同樣的swfs。 – Artemix
我明白,但是,Action類在構造函數中需要一個EntityVO自定義對象,爲什麼這個工作呢?,它不應該。 – Artemix