Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save and load objects in Flash Adobe Air
    primarykey
    data
    text
    <p>I feel like I'm a little out of my depth here - I need to figure out a way to allow users to save their galaxy in an outer space game that I'm building. At the most basic level, I need to write the randomly generated galaxy (which is an instance of a custom class) to disk and then read it from the disk later. I've not used Air's filestream abilities before and I'm having a bit of trouble. My code:</p> <pre><code> public function saveGame(e:MouseEvent):void { trace("save"); var file:File = File.desktopDirectory.resolvePath("test.sv"); var fileStream:FileStream = new FileStream(); fileStream.open(file, FileMode.WRITE); fileStream.writeObject(gal); fileStream.close(); } public function loadGame(e:MouseEvent):void { trace("load"); var file:File = File.desktopDirectory.resolvePath("test.sv"); if (file.exists) { var obj:Object; var fileStream:FileStream = new FileStream(); fileStream.open(file, FileMode.READ); obj = fileStream.readObject(); fileStream.close(); trace(obj); } } </code></pre> <p>The object "gal" is my galaxy, and I've verified that it's a valid instance of my object (it contains children and it contains many variables) but for some reason the file created on the desktop is only 1 byte - obviously too small to contain any info.</p> <p>When I trace the object in the second function it's null.</p> <p>Any help on this would be greatly appreciated, as it's very difficult to find this information clearly explained for a beginner such as me. </p> <p>Thanks for any insight you may have.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload