3

Is there a way to save an application state for save files in AIR for the desktop (Flex /AS3)?

Thanks

ThinkNewDev
  • 668
  • 9
  • 28
  • Can you explain what exactly you want to save and when it should be loaded? – Valentin Simonov Feb 12 '12 at 19:56
  • I want to save certain arrays, XMLLists, and diplayobjects to a save file that can be loaded back in. But I was hoping there was an easy way to save everything on screen for reloading – ThinkNewDev Feb 12 '12 at 20:00
  • There is no such possibility. You can only write script that will save object You choose to ByteArray and save file . – turbosqel Feb 12 '12 at 20:38
  • Will saving an object as a bytarray save all children and properties associated with them? – ThinkNewDev Feb 12 '12 at 20:46

1 Answers1

2

You need to make sure all your classes are serializable, then serialize them and save them to a file when exiting the application.

On starting the application again, you deserialize the objects - in effect instantiating all objects and assigning all their previous properties again.

This can be rather hard to retro-fit to an existing application since your code must adhere to a few rules. For instance, your class constructors cannot accept any arguments and your objects must have public properties or they will not be serialized.

This article should get you up to speed on object serializaion in as3: http://jacksondunstan.com/articles/1642

david.emilsson
  • 2,313
  • 1
  • 20
  • 24
  • Those restrictions sound rather horrible. I would just use a home-made serialization-system. Maybe an interface that has two methods; one that creates an object graph out of itself (for saving as JSON) and one (static?) that generates an instance from an object graph. – Jonatan Hedborg Feb 13 '12 at 09:25