# ListBox and TXT Files

**URL:** <https://forum.kirupa.com/t/listbox-and-txt-files/4639>\
**Category:** flash\
**Created:** [August 15, 2002, 1:55am UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639 "2002-08-15T01:55:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaztank](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gaztank](https://forum.kirupa.com/u/Gaztank)\
**Post date:** [August 15, 2002, 1:55am UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/1 "2002-08-15T01:55:18Z")

</div>

Here’s a question about ListBoxes.  
I want to have a listbox and a dynamically loading textbox on the scene. For each item in the listbox, how do i make it open a different text file that will load it’s contents in the 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:** [August 15, 2002, 2:46pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/2 "2002-08-15T14:46:08Z")

</div>

Hmm… if I got it correctly

your textboxes will have variables

textbox1  
textbox2  
textbox3  
textbox4

when your listbox item is selected

loadvariables(“mytext.txt”)

your mytext.txt contains a line that says textbox=firstbox;

---

<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:** [August 15, 2002, 4:49pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/3 "2002-08-15T16:49:05Z")

</div>

could u elaborate on that?

i have 1 dynamic text box, and a list/combo box.  
maybe it’s just that i’m not too familiar with these things yet, but it seems to me that from Kirupa’s tutorial that for every item u select on ur list/combo box, it will only perform one action. and from that one action (function), you have to be able to make it unique for each item.

confusion … ?!?

---

<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:** [August 15, 2002, 5:17pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/4 "2002-08-15T17:17:19Z")

</div>

maybe seeing my code might be useful for giving me pointers and finding the booboos.

in my combobox, i have set labels, and i have set data. i’ve put in months for the data with the same name as the variables in my text file, hoping that when i use selectedItem.data i can use that to call to that variable in the text.

the following is my code:

loadText = new loadVars();  
loadText.load(“Text/Journal.txt”);  
loadText.onLoad = function() {  
TextBox.html = true;  
TextBox.htmltext = this.august;  
};  
function displayDetails© {  
TextBox.htmltext = this.c.getSelectedItem().data;  
}  
ComboBox.setChangeHandler(“displayDetails”);

the first part is just the loading of the text file into the dynamic textbox. the “TextBox.htmltext = this.august” works fine, it’s just that when i do the next TextBox.htmltext= it won’t display the same result as before.

c.getSelectedItem().data should equal ‘august’ should it not? cuz i’ve actually put august as the peice of data in the combobox …  
so why does the second TextBox.htmltext not give me the same result as the first one ?

stumped …

---

<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:** [August 15, 2002, 5:23pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/5 "2002-08-15T17:23:13Z")

</div>

its all about the onChange handler. I did misinterpret your question at first, though…

the file is attached, but here is the code for anyone reading. The code assumes a dynamic textbox on the root with a variable called textbox.

put this in the first frame of your movie

```auto

function onChange(flistbox){
_root.textbox=flistbox.getselecteditem().label;
}

```

Of course, you must set the change handler for the listbox in the properties panel to onChange  
see example attached.

---

<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:** [August 15, 2002, 6:42pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/6 "2002-08-15T18:42:58Z")

</div>

what u’ve shown me is just changing the textbox to the label of the item in the listbox …

er … i can understand what u’ve done, but the thing is the variables in the .txt file aren’t loading into the dynamic textbox …

i guess the main problem is i dunno how to code it so that what appears in the dynamic text box is not the label, but a variable from the .txt file …

---

<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:** [August 15, 2002, 8:09pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/7 "2002-08-15T20:09:25Z")

</div>

aaaaaaaaaaaaah… well, Im a dunce, at did not understand… you answer is still in the onChange command, however.

```auto

function onChange(flistbox){
	
	mylist=flistbox.getSelectedItem().label
	if(mylist=="apples"){
		loadvariables("apples.txt",_root);
		trace("apples");
	}else if (mylist=="oranges"){
		loadvariables("oranges.txt",_root);
		trace("oranges");
	}else if (mylist=="grapes"){
		loadVariables("grapes.txt",_root);
	}else if (mylist=="pears"){
		loadVariables("pears.txt",_root);
}
		
}

```

or… use switch, more efficient…

```auto

function onChange(flistbox){
	
	mylist=flistbox.getSelectedItem().label
	switch(mylist){
		case "apples":
		loadvariables("apples.txt",_root);
		break;

	                case "oranges":
		loadvariables("oranges.txt",_root);
	                break;

	                case "grapes":
		loadVariables("grapes.txt",_root);
                                break;

                                case "pears":
		loadVariables("pears.txt",_root);
		break;
}
		

}

```

---

<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:** [August 15, 2002, 8:42pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/8 "2002-08-15T20:42:59Z")

</div>

i’ve already loaded the .txt file already at the beginning of the frame action, so instead of using loadvariables grape.txt and apples.txt i’ve put in

TextBox.htmltext = this.current;

where ‘current’ is a variable in my .txt file (and all my variables are stored within this one .txt file). my problem is just getting the variable to display in the text box

if i used the above line of code as a frame action, it works perfectly fine, but once i make it as part of the onChange function, it does not work. I think this is just a case of inexperience with the scripting.

I hope i’m not getting on ur nerves :x

---

<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:** [August 16, 2002, 3:05am UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/9 "2002-08-16T03:05:41Z")

</div>

allright, buddy… how 'bout you save me some time and attach your fla, please.

thx.

🙂

---

<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:** [August 16, 2002, 3:26am UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/10 "2002-08-16T03:26:09Z")

</div>

hehe, actually i got it figured out … it wasn’t the greatest idea but it fixed the problem … what i did was just load the file every time and put the variable into the textbox everytime … as opposed to loading the text file once, and then putting the variable into the textbox when called … kinda redundent to keep calling it everytime an item is selected, but it works tho … hehe

---

<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:** [August 16, 2002, 3:05pm UTC](https://forum.kirupa.com/t/listbox-and-txt-files/4639/11 "2002-08-16T15:05:11Z")

</div>

great! I’m glad you have it all worked out!  
🙂
