Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tracing a dynamic text value

Status
Not open for further replies.

flashbbeb

MIS
Mar 29, 2005
106
0
0
US
I'm not new to loadVariables, and I can load &variable values from a text file into a dynamic text box, BUT how do I trace the value and/or use it later on in the script?

I've got a dynamic text box called answerChoice, connected to variable &numberofanswers. It populates with a value of 4 from the txt file just fine, but why can't I do any of the following?

Code:
//simple trace on the var
trace(numberofanswers);

//assigning the text value to a var
answerCh = answerChoice.text;
trace(answerCh);

//putting the value of numberofanswers into another var
crap="";
crap = numberofanswers;
trace(crap);
 
Your trace doesn't work because the variable "numberofanswers" has not yet populated when you do the trace.

"loadVariables" is Flash 4 and it does not have the method to check the loading status. If you can, use the current "LoadVars" Class instead - it has LoadVars.onLoad handler which is invoked when the data loading is completed.

If you want to stick to loadVariables, you have to use an Interval or onEnterFrame to check if your variable is loaded again and again until it's done. Not nice.

Kenneth Kawamoto
 
Kenneth, thanks for helping me into the 21st century!

From what I've looked at briefly and tried, I've only been able to get the dynamic text box to fill (just as before), but I can't trace it outside of the onLoad function that populates the box.

Code:
var theData = new LoadVars();
theData.onLoad = function(){
	numberofanswers.text = this.numberofanswers;
	
}
theData.load("info.txt");
 
Again your trace() is called before the data is loaded.

theData.load("info.txt");
trace(theData.numberofanswers);

This doesn't work because when trace() is called the data is not yet loaded. Flash does not wait things to complete at each line of code when loading the data (it's called "asynchronous").



Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top