无法在adobe air ELS中获取已保存的数据

时间:2012-11-03 20:04:18

标签: actionscript-3 flex air adobe

我正在尝试使用以下代码保存并从adobe air应用程序获取数据。但它只是保持警报只是未定义。有人能找到错误吗?

            function saveData(n, v){
                var bytes = new air.ByteArray(); 
                bytes.writeUTFBytes(v); 
                return air.EncryptedLocalStore.setItem(n, bytes);   
            }

            function getData(n){
                var storedValue = air.EncryptedLocalStore.getItem(n); 
                return air.trace(storedValue.readUTFBytes(storedValue.length));
            }

            saveData('item1', 'value1');
            alert(getData('item1'));

1 个答案:

答案 0 :(得分:2)

尝试删除air.trace功能

function saveData(n:String, v:String):void
{
    var bytes = new air.ByteArray(); 
    bytes.writeUTFBytes(v);

    air.EncryptedLocalStore.setItem(n, bytes);   
}

function getData(n):String
{
    var storedValue = air.EncryptedLocalStore.getItem(n); 

    return storedValue.readUTFBytes(storedValue.length);
}

saveData("item1", "value1");
alert(getData("item1"));