# Another Dynamic Text Question

**URL:** <https://forum.kirupa.com/t/another-dynamic-text-question/406>\
**Category:** flash\
**Created:** [July 16, 2002, 6:56pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406 "2002-07-16T18:56:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ghandigu](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@Ghandigu](https://forum.kirupa.com/u/Ghandigu)\
**Post date:** [July 16, 2002, 6:56pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/1 "2002-07-16T18:56:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2002, 8:48pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/2 "2002-07-16T20:48:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2002, 10:21pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/3 "2002-07-16T22:21:50Z")

</div>

cycom, nice tip!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2002, 10:47pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/4 "2002-07-16T22:47:42Z")

</div>

cycom,

Thanks man. That was it.

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 3:19am UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/5 "2002-07-17T03:19:00Z")

</div>

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 :

```auto
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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 8:02am UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/6 "2002-07-17T08:02:59Z")

</div>

good place to use a LoadVars object.

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 4:27pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/7 "2002-07-17T16:27:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 4:54pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/8 "2002-07-17T16:54:38Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 5:12pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/9 "2002-07-17T17:12:26Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 6:36pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/10 "2002-07-17T18:36:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2002, 6:41pm UTC](https://forum.kirupa.com/t/another-dynamic-text-question/406/11 "2002-07-17T18:41:02Z")

</div>

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:
