0
我一直在許多自定義類上使用ByteArray,我一直需要存儲/加載,但是ByteArray似乎永遠不會序列化正確擴展MovieClip的自定義類/對象。讀取時總是缺少數據或空值。序列化擴展MovieClip的類> DisplayObject
我讀過這裏,AMF無法序列化displayObjects,並想知道是否有一個很好的解決方案,我可以使用? (分流數據OBJ到JSON和餵養字符串返回到我的儲蓄短。)
進入和ByteArray
public static function _SaveTRData(trData:Object):String{
if(_trackerComp == null){
return "ERR: -1";
}
var resp:String = "";
var bytes:ByteArray = new ByteArray();
bytes.writeObject(trackerData);
resp = _trComp.SaveTRData(bytes);//to SQLlite db methods
if(resp != ""){
_tr.UpdateStatusMessage(resp);
}
return resp;
}
public static function _GetTRData(fileName:String):Object{
if(_trComp == null){
return null;
}
var resp:ByteArray = _trComp.GetTRData(fileName);//from SQLlite db methods
resp.position = 0;
return(resp.readObject());//returned object is passed into graphics pipeline to redraw contained data elements
}
對象(S)的輸出被存儲
var trackerData:Object = {arrPolys:new Array(), arrLabels:new Array()};
trackerData.arrPolys = maps.arrPolys();
trackerData.arrLabels = maps.arrLabels();
//Truncated, contains more arrays of objects...
//Each object in arrPolys is a
public class Polygon extends MovieClip{
//3 private uints
//3 private bools
//1 private array
//3 private custom class Line which extends Shape
}
//Each object in arrLabels is a
public class Label extends MovieClip{
//Several private strings
//Several private dynamically generated graphic components
//Several private label specifications (Strings, Ints, Booleans)
}
顯示一些代碼?你在使用registerClassAlias嗎? – Nemi
經過一些測試後,ByteArray將不會序列化擴展MovieClip的類(一個顯示對象)中的任何數據。 我正在用IDataInput和IDataOutput調查IExternalizable,但保持與readExternal()和writeExternal()的簽名錯誤 – Reahreic
如果您需要將MovieClip存儲在ByteArray中,那麼您的設計很糟糕。你應該提取一些數據模型。該數據模型可以存儲爲ByteArray。數據恢復時應更新MC。看看Model-View-Controller或Model-View-Presenter模式。 –