Another Dynamic Text Question

I too am trying to load variables from a .txt file

I do so with loadvariables ("text.txt,0)

text.txt has for example

test1=blah
test2=blahblah

And I CAN get it to these into dynamic text boxes named:
“test1” and “test2” respectivly.

But how do I now use the values in actionscript?

Say I want a script which does an action “IF” test2 = blah?

So…

1 - how do I use the values of the text boxes?

and

2 - Do I have to use text boxes as an intermediary or can I Load the Records from my text file into an array?

Thanks in advance.

Ghandigu

Heyya,

your problem might be, that the variables are not loaded when you try to use them. It takes quite some frames before you actually can use the loaded variables in actionscript.

Example:

content of text.txt:

var1=abc

the following commands put in the same frame will produce an empty box evoked by the trace command:

loadVariables (“text.txt”, _root);
trace(var1);

A trace command directly after a loadVariables-command shows you nothing, because the variables actually did not load yet.

Whereas the same trace command put in frame20 (or so) will show a box containing “abc” (the value of var1)

A dynamic Textbox actually shows the variables’ value, since you don’t really recognize the time it takes for the variables to load and the textbox gets currently updated.

Hope this helps !

Cheers,
cycom

cycom, nice tip!

cycom,

Thanks man. That was it.

I guess the delay it’s not as apparent when the data is loading into a textbox

OK, I think I understood that this is one of the situations when you have to use onClipEvent (data). So it could be something like that :

myclip.loadVariablesNum("text.txt", 0); 
myclip.onData = function { 
    if (var1 == 5) // do something
}

Not sure at all though. I’d really like it if somebody could explain it once for all.

pom :asian:

good place to use a LoadVars object.


daGoods = new LoadVars();
daGoods.load("vars.txt");
daGoods.onLoad = function(){
	for(i in this){
		trace(i+":"+this*);
	}

Very neat, but works in flash MX only, i suppose?

Got another question, though:

Is there an easier way to use a numeric value from a textfile, than to use – int(substring(variable,0,1)) – ? Cause otherwise there seems to be a problem with the linefeed/carriage return characters coming from the textfile plus the variable is a string and not an integer.

Cycom

isn’t this the mx forum?

Number(string); will convert a string to a number, but only if it’s formatted as such

if you are getting carriage returns in your variables, why not remove them from the text file? it should probably read:

test1=blah&test2=blahblah

the way it’s written earlier meant that you got one variable:

test1 = “blah
test2=blahblah”

Now that’s interesting. Why is it better to use loadVars ? Because basically, you just turned the onData handler into an onLoad handler, no ? Just curious.

pom :asian:

You’re right… the onData verifies that data was actually acquired. That makes a huge difference in the code. I’m sure you can see the immediate benefits.

I can’t see the benefit, Inigo ! It just seems to me that both methods work the same way, so why is it better to use a loadVars object ?

pom :asian: