I am trying to reference a shared object (one that saves data), but whenever I try to, I get a crash.
This code works fine:
var var1:Object = { value:1 };
var varRef:Object = var1;
if(var1.value == 1) {
varRef.value = 50;
}
trace(varRef.value); // outputs 50;
trace(var1.value); // outputs 50;
But when I try to use shared objects, it doesn’t work.
import flash.net.SharedObject;
var iapso:SharedObject = SharedObject.getLocal("purchases");
var varRef:Object = iapso.data.testing;
varRef = 90
trace ("The shared value is " + iapso.data.testing);
trace ("This should mirror it" + varRef);
If you’re able to figure out the issue, please post a fixed version.
Thanks.
You must come from a programming background where pointers can be dereferenced.
In this case,
varRefis notvarRef = &iapso. Setting its value does not change the value ofiapso.data.testing;Initially, you set
varRefas a pointer toiapso.data.testing:Then, you immediately change it to a constant value object literal
90:This does not set the value of
testingto 90 – this changes the value ofvarRef.You could set
varReftoiapso.data, then settestingas in:Then, the following would produced expected results: