Believe in Bigfoot? Well, I swear I’ve seen a big hairy LoadVar running of and refusing to give up any of his variables. Here’s my evidence:
Here’s how things should work:
------ example code start -----
var testVar = “initial”;
function alter(){
testVar = “changed”;
}
alter();
trace(testVar);
------ example code end -----
testVar in this case traces as “changed”. All well and good. No hairy beasts found.
Lets see what happens if I call function alter() within a loadVars function:
------ example code start -----
ar testVar = “initial”;
function alter(){
testVar = “changed”;
}
server = new LoadVars();
server.onLoad = function(ok){
if (!ok) return trace("Server error!");
alter();
}
server.load(“mypath.php”);
trace(testVar);
------ example code end -----
You’d expect testVar to equal “changed”, right? Well it doesn’t. It equals “initial”. I don’t know what your beliefs are, but that’s looking pretty hairy to me. Here’s some more testing:
------ example code start -----
var testVar = “initial”;
function alter(){
testVar = server.valid;
trace("testVar within alter function is: "+testVar);
testOutput = “should have a value”;
}
function simplealter(){
testVarTwo = “changed”;
}
server = new LoadVars();
server.onLoad = function(ok){
if (!ok) return trace("Server error!");
alter(server.valid); //server.valid == 0 for your information
trace("server.valid is: "+server.valid);
simplealter();
}
server.load(“mypath.php”);
trace("testVar in the end is: "+testVar);
trace("testOutput in the end is: "+testOuput);
trace("testVarTwo in the end is: "+testVarTwo);
------ example code end -----
Here’s what all this outputs:
testVar in the end is: initial
testOutput in the end is: undefined
testVarTwo in the end is: undefined
testVar within alter function is: 0
server.valid is: 0
the motto of the story is - you can’t use what you load with load vars outside of a function. Unless you know the secret sauce!.. help please. This one is killing me. Plus I don’t like to get into conspiracy theories.