开发者

Is it possible to store an Array into an EncryptedLocalStore item? AIR

开发者 https://www.devze.com 2023-04-09 07:47 出处:网络
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 ite开发者_如何学Pythonm then get it later when I re-open t

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 ite开发者_如何学Pythonm then get it later when I re-open the app?


EncryptedLocalStore.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);
EncryptedLocalStore.setItem('somekey', byteArray);

Hope this helps.

Update: Added code to retrieve the array back.

var byteArray:ByteArray = EncryptedLocalStore.getItem('somekey');
var array:Array = byteArray.readObject() as Array;

Update: For custom classes.

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


I have found that it is easiest to to serialize the Array to a string and then store that string in the ELS. Then when you pull it out deserialize it back into an Array.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号