0
votes

I'm pretty inexperienced with actionscript, and I'm having the hardest time trying to figure out how to load variables from a file and send it to a dynamic text box.

The content of an external file, "varload.txt", is "name1=John".

Here is actionscript of my flash file:

myVars = new LoadVars();
myVars.onLoad = function(){
    trace(this.name1); //prints "John" as expected
    myname=this.name1;
}
myVars.sendAndLoad("varload.txt", myVars);

mytextbox.text=myname; //undefined

I'm guessing it's a scope issue, but I can't find much online about global variables in actionscript, so I'm not sure how to fix this.

How do I get mytextbox.text to equal John?

1

1 Answers

1
votes

The issue is that onLoad is asynchronous (called once the file has loaded, not immediately).

You'll have to define the text within the onLoad function:

myVars = new LoadVars();
myVars.onLoad = function()
{
    mytextbox.text = this.name1;
}

myVars.sendAndLoad("varload.txt", myVars);

With your code, you're trying to set the content of the text box to being data that doesn't exist / hasn't loaded yet.