问题描述
我要救我的数组的strucure并加载它下一次我打开我的AIR应用程序。有没有办法将其存储到EncryptedLocalStore项目,然后得到它后,当我重新打开应用程序?
I want to save my Array's strucure and load it the next time I open my AIR application. Is there a way to store it to an EncryptedLocalStore item then get it later when I re-open the app?
推荐答案
EncryptedLocalStorage.setItem()方法需要一个字节数组。为了存储阵列,只是使用ByteArray.writeObject()方法(如http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html#writeObject())你的数组转换为ByteArray - 然后坚持相同的ELS
EncryptedLocalStorage.setItem() method takes a byte array when storing contents. To store an array, just use ByteArray.writeObject() method (as described in http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html#writeObject()) to convert your Array to a ByteArray - and then persist the same to the ELS.
var array:Array = getArray();
var byteArray:ByteArray = new ByteArray();
byteArray.writeObject(array);
EncryptedLocalStorage.setItem('somekey', byteArray);
希望这有助于。
Hope this helps.
更新:增加了code检索阵列背
Update: Added code to retrieve the array back.
var byteArray:ByteArray = EncryptedLocalStorage.getItem('somekey');
var array:Array = byteArray.readObject() as Array;
更新:对于定制类
Update: For custom classes.
在你想自己的自定义类序列化到ByteArray的情况下,您可能需要调用registerClassAlias()写对象则ByteArray之前。对于如:
In case you want to serialize your own custom classes to the ByteArray, you may have to call registerClassAlias() before writing the object to the ByteArray. For eg.
registerClassAlias("com.example.eg", ExampleClass);
这篇关于是否有可能存储阵列到EncryptedLocalStore项目?空气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!