How do I share a javascript object between different pages in Adobe AIR?

為{幸葍}努か 提交于 2019-12-11 15:55:11

问题


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.


回答1:


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();
}



回答2:


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 ...



来源:https://stackoverflow.com/questions/193130/how-do-i-share-a-javascript-object-between-different-pages-in-adobe-air

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!