loadVars puzzle

To my geeky friends…

I’ve come across this puzzle, I hope you guys can help me figure it out.

It really is quite simple. I have a text file called sites.txt. I want to load the variables from that file and use them in my movie. I have a dynamic text box on my _root. I called it Mybox.

Here’s the puzzle.

This doesn’t work


newload=new loadVars();
newload.load("sites.txt");
newload.onLoad=function(){
	trace(newload.toString());
	
}
_root.mybox.text=newload.hello;

But, this one works.


newload=new loadVars();
newload.load("sites.txt");
newload.onLoad=function(){
	trace(newload.toString());
	_root.mybox.text=newload.hello;
}

Notice that the only change is the location of the “_root.mybox.text=newload.hello;” piece of code. However, this variable is supposed to be available anywhere else in the movie.

Once we talk about this one, I’ll give you a second, similar puzzle with loadvariables();

Geek reporting, Sir.

Elementary, my dear Watson. In the first piece of code, you’re trying to access newload.hello but it’s empty. The loading isn’t done yet. And even if it was done (that is to say instantaneous), the data is available on the next frame.

In the second piece of code, you access the data when it is actually loaded (onLoad…).

Waiting for the other one… :cowboy:

Interesting, interesting… see, in my mind, all was loadead. I realize that it is running all the code before the load ends. Okee…

I will load the second later… :slight_smile:

hehe :slight_smile: