Search code examples
actionscript-3apache-flexairadobe

Unable to get a saved data in adobe air ELS


I am trying to save and get data from an adobe air application with the following code. buts its just keep alerting only undefined. Can someone find the error?

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

Solution

  • try removing the air.trace function

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