I don’t know why the value of my variable my_str is undefined outside of this function:
loadText = new loadVars();
loadText.load(“data.txt”);
loadText.onLoad = function(success) {
if (success) {
my_str = this.name;
trace(my_str)//my_str has the right value
} else {
trace(“Error loading data”);
}
}
trace(my_str)//my_str is undefined
ps: I tried making my_str a global function or even defining it as _root.my_str but I always get the same result…it’s undefined outside the function…I need that value for something else so…
anyone has a clue???
the reason for an onLoad function is that it allows you a place to put code waiting for your content to load. Why you need to wait is because loaded values from a text file arent loaded right away. Because they arent loaded right away, any code run in that frame not in the onLoad function will have no access to what was loaded because it was run all at once - all at that time that it was told to load in the first place. Because of that your trace(my_str) on the timeline will get run before the onLoad is called meaning it will have no value to find.