how to create a JSON file for any object and save it on disk. after some days retrieve it back?
Asked
Active
Viewed 1,287 times
2 Answers
1
To write to a shared object
var so:SharedObject = SharedObject.getLocal("mySharedObject");
so.data.storedJSON = myJSON;
so.flush();
To retrieve it back elsewhere
var so:SharedObject = SharedObject.getLocal("mySharedObject");
myJSON = so.data.storedJSON;
convert to ByteArray
save
read a this documentation: registerClassAlias
registerClassAlias("com.myDomain", MyClass);
var myClass:MyClass = new MyClass();
var ba:ByteArray = new ByteArray();
ba.writeObject(myClass);
so.data.byteArray = ba;
ba.position = 0;
read
myClass = so.data.byteArray.readObject();

bitmapdata.com
- 9,572
- 5
- 35
- 43
-
but cookies are not store permanently.how save in database in some UiObject and retrieve it back? – Devendra Feb 08 '13 at 08:31
-
Ok, I modified. method using a SharedObject. check out please. – bitmapdata.com Feb 08 '13 at 08:34
-
Is not well understood. A little more clearly, let us know. you want save UIComponets? – bitmapdata.com Feb 08 '13 at 08:38
-
so.data.object form not able cast in UIform for UICOmponents. – Devendra Feb 08 '13 at 08:39
-
i asked a question few days ago and implement that but i was not able to object in same class..http://stackoverflow.com/questions/14135313/save-application-state-in-diagram-application – Devendra Feb 08 '13 at 08:42
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24177/discussion-between-dev-and-bitmapdata-com) – Devendra Feb 08 '13 at 09:52
0
-
i used sharedOject class but retrieve data from amf file in row form. i was not able to cast this object into DisplayObjects. – Devendra Feb 08 '13 at 08:28
-
You won't be able to `JSON.serialize()` a DisplayObject, it's plain normal. They contain too much links that make you lose data integrity if you save and then load a DisplayObject. So, you have another problem, the solution is [IExternalizable](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/IExternalizable.html), it requires a lot of code but lets you save your entire data structure and then restore it object by object. – Vesper Feb 08 '13 at 08:41