如何在Adobe AIR中的不同页面之间共享javascript对象?

时间:2022-12-01 16:40:13

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?

我想将一个自定义对象附加到应用程序,以便我可以在adobe air中的不同html页面之间保留状态。这可能吗?


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.

我要求一个完整的解决方案来将一个自定义js对象存储在内存中,并在从应用程序沙箱加载的页面之间保留它,但除非我使用不太令人愉快的iframe,否则无法完成,因为我必须添加很多东西到了桥。 Anoter方式可能是对从文件中读取html的页面进行部分呈现,但这会暴露出许多令人不快的错误+你无法动态地在dom中编写脚本标记。这是一个残缺的平台。

2 个解决方案

#1


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


0  

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

如果它只包含字符串中有意义的值,则可以将其存储为cookie或者可能存储在服务器端会话中......

#1


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


0  

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

如果它只包含字符串中有意义的值,则可以将其存储为cookie或者可能存储在服务器端会话中......