Reputation: 835
Working with an adobe air app for the first time. Dont know whats the error with the following code. It is not alerting the "no" value.
Please see, the saveData()
and getData()
are from this question.
function check(){
var d1 = getData('item1');
var d2 = getData('item2');
if (d1 && d2) {
alert('yes');
} else {
alert('no');
}
}
saveData('item1','value1');
saveData('item2','value2');
// I know that its ridiculous to save the data and then reset it.
// But This is how the main code works. sorry.
air.EncryptedLocalStore.reset();
check();
Upvotes: 0
Views: 76
Reputation: 17217
You're clearing your data from ELS before checking it:
flash.data.EncryptedLocalStore.reset(): Clears the entire encrypted local store, deleting all data.
I'm not sure why you are doing this or how it is even working for you (as you claim it is) but if you say it's required than it's required. Assuming this is actually working and not causing you problems you many want to revise this logic since it's very strange.
Also, the arguments passed to the condition should be typed as strings and the condition should check if the length of those strings are not zero.
try this:
function check():void
{
var d1:String = getData("item1");
var d2:String = getData("item2");
if (d1.length && d2.length)
{
alert("yes");
}
else
{
alert("no");
}
}
saveData("item1","value1");
saveData("item2", "value2");
// This is ghetto!
air.EncryptedLocalStore.reset();
check();
To avoid errors and problems, you should strictly type your code.
Upvotes: 1
Reputation: 15955
When you evaluate the expression d1 && d2
you are performing a logical AND operator.
&& (logical AND) — Returns expression1 if it is false or can be converted to false, and expression2 otherwise.
Presumably when you test if(d1 && d2)
the condition is true, alerting "yes" as both instances were loaded.
Only upon failure, such as if d1
or d2
were null
would this alert "no".
Upvotes: 1