views:

572

answers:

2

I'd like to have a custom object attached to the application so I can preserve state in it between different html pages in adobe air. Is this possible?


I was asking for a fullblown solution to store a custom js object in memory and persist it between pages loaded from the application sandbox, but this cannot be done unless I use iframes which is not very pleasant, since I have to add a lot of stuff to the bridge. Anoter way may be to do partial rendering of the page filled with html read from files, but this exposes a lot of unpleasant bugs + you cant write script tags in the dom dynamically. It's a crippled platform.

A: 

What sort of object ?-)

If it only holds values that are meaningful in a string, you could store it as a cookie or perhaps in a serverside session ...

roenving
+1  A: 

Perhaps you could try attaching the object on the user's machine. There is a tutorial online that seems like it could help:

http://corlan.org/2008/09/02/storing-data-locally-in-air/

Example from the site:

//write an Object to a file
private function writeObject():void {
    var object:Object = new Object();//create an object to store
    object.value =  asObject.text; //set the text field value to the value property
    //create a file under the application storage folder
    var file:File = File.applicationStorageDirectory.resolvePath("myobject.file");
    if (file.exists)
        file.deleteFile();
    var fileStream:FileStream = new FileStream(); //create a file stream
    fileStream.open(file, FileMode.WRITE);// and open the file for write
    fileStream.writeObject(object);//write the object to the file
    fileStream.close();
}
Dimitry Z