# External txt

**URL:** <https://forum.kirupa.com/t/external-txt/102171>\
**Category:** Uncategorized\
**Created:** [February 20, 2004, 2:54pm UTC](https://forum.kirupa.com/t/external-txt/102171 "2004-02-20T14:54:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![El\_Bicho](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@El\_Bicho](https://forum.kirupa.com/u/El_Bicho)\
**Post date:** [February 20, 2004, 2:54pm UTC](https://forum.kirupa.com/t/external-txt/102171/1 "2004-02-20T14:54:59Z")

</div>

I have a text file called “names.txt”. It has several variables called name1, name2… etc.

In my fla I have a text box called firstname where names should appear.

This is the code:

```auto

names = new loadVars();
names.load("names.txt");
button.onPress = function() {
	a++;
	firstname.text = names.eval("name"+a);
};

```

Nothing happens…

Any idea?

Thanks.

---

<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:** [February 20, 2004, 6:56pm UTC](https://forum.kirupa.com/t/external-txt/102171/2 "2004-02-20T18:56:05Z")

</div>

It’s most likely because you haven’t declared a. You’re increasing a with one, but a doesn’t exist. Therefore it doesn’t work.

Another thing to remember is that the data might not be loaded yet when that button is being pressed. It is safer to only set the onPress handler when the file has loaded. This is done using onLoad:

```auto

a=0;
names = new loadVars();
names.load("names.txt");
names.onLoad = function(){
button.onPress = function() {
        a++;
        firstname.text = names["name"+a];
}
}

```
