gpt4 book ai didi

actionscript-3 - Adobe AIR - 保存本地数据

转载 作者:行者123 更新时间:2023-12-05 00:37:05 25 4
gpt4 key购买 nike

我想将变量保存到加密的本地存储。
此示例有效,但如何扩展它以保存 1 个以上的变量?

// To save variable to ELS (EncryptedLocalStore)

function saveItems() {
var m1:String = "my item 1";
// HOW TO ADD THESE?:
// var m2:String = "my item 2";
// var m3:String = "my item 3";
// var m4:String = "my item 4";
//
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(m1);
EncryptedLocalStore.setItem("item1", bytes);
}

// Read it from ELS
function getItems() {
var storedValue:ByteArray = EncryptedLocalStore.getItem("item1");
//
trace(storedValue.readUTFBytes(storedValue.length));
}

谢谢。

最佳答案

冲洗并重复您已有的内容,并通过将常用功能移动到自己的方法中来避免重复代码:

private function saveItems():void {
var m1:String = "my item 1";
var m2:String = "my item 2";
var m3:String = "my item 3";
var m4:String = "my item 4";

saveItem("item1", m1);
saveItem("item2", m2);
saveItem("item3", m3);
saveItem("item4", m4);
}

private function saveItem(key:String, value:String):void
{
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(value);
EncryptedLocalStore.setItem(key, bytes);
}

几个不错的引用:

http://www.adobe.com/devnet/air/ajax/articles/encrypted_local_store.html

http://help.adobe.com/en_US/air/reference/html/flash/data/EncryptedLocalStore.html

关于actionscript-3 - Adobe AIR - 保存本地数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7363234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com