1

how to create a JSON file for any object and save it on disk. after some days retrieve it back?

Devendra
  • 1,864
  • 6
  • 29
  • 49

2 Answers2

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
0

Use SharedObjects. Read up on them here.

Vesper
  • 18,599
  • 6
  • 39
  • 61
  • 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