# Populate combobox

**URL:** <https://forum.kirupa.com/t/populate-combobox/6965>\
**Category:** flash\
**Created:** [October 21, 2002, 3:38am UTC](https://forum.kirupa.com/t/populate-combobox/6965 "2002-10-21T03:38:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![waffe](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@waffe](https://forum.kirupa.com/u/waffe)\
**Post date:** [October 21, 2002, 3:38am UTC](https://forum.kirupa.com/t/populate-combobox/6965/1 "2002-10-21T03:38:16Z")

</div>

Is there a way to load an external txt file into a combo box.

---

<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:** [October 21, 2002, 9:06am UTC](https://forum.kirupa.com/t/populate-combobox/6965/2 "2002-10-21T09:06:03Z")

</div>

Well of course. Why not? After all it is just text that you are entering in your combobox…

pom 😏

---

<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:** [October 21, 2002, 6:49pm UTC](https://forum.kirupa.com/t/populate-combobox/6965/3 "2002-10-21T18:49:10Z")

</div>

Well, would you mind letting me in on your secret.=)

---

<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:** [October 21, 2002, 8:48pm UTC](https://forum.kirupa.com/t/populate-combobox/6965/4 "2002-10-21T20:48:34Z")

</div>

Open your ears…

You need: a text file with the things you want to put in the combobox. I called the file combotext.txt and it contains

> a=pom\_wonderful&b=supra\_extraordinary&c=kirupa\_busy&d=lost\_lost  
> They are formatted like so: varName=label\_data.

Then in the flash file, you need a combobox, instance name myCombo.

Finally, some code in the 1st frame of the movie:

```auto
//create loadvars object
myLV=new LoadVars();
myLV.onLoad=function(){
	//gets all the elements of the txt file
	for (var i in myLV){
		trace (i+": "+this*);
		//split the label from the data
		var a=this*.split("_");
		//fill the combobox
		myCombo.addItem(a[0],[a[1]]);
		//for the demo
		myCombo.setChangeHandler("display");
	}
}
myLV.load("combotext.txt");

display=function(c){
	//display the data of the selected item
	var res=c.getSelectedItem().data[0];
	trace(res);
}

```

Tada!! There’s just one little problem, I let you find it :cowboy:

pom 😛

---

<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:** [October 21, 2002, 10:37pm UTC](https://forum.kirupa.com/t/populate-combobox/6965/5 "2002-10-21T22:37:05Z")

</div>

I’ll be back.: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:** [October 22, 2002, 9:04am UTC](https://forum.kirupa.com/t/populate-combobox/6965/6 "2002-10-22T09:04:07Z")

</div>

My pleasure…

---

<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:** [October 23, 2002, 3:24am UTC](https://forum.kirupa.com/t/populate-combobox/6965/7 "2002-10-23T03:24:44Z")

</div>

Problem 1

```
The data values from the text files are reversed.

```

Ok, I have changed the .split"\_" to .split"|"

My txt file reads,

a=song1|1&  
b=song2|2&  
c=song3|3&  
d=song4|4

When I render the fla and select song1, I receive an output of 4.  
It should be 1?

Problem 2

I always have 1 extra label in the list box.  
You see in my text file I only have 4 rows, but when I render the fla I have 5 rows in the listbox and the 5th row has an output of undefined.

Well what do you think?

: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:** [October 23, 2002, 3:45am UTC](https://forum.kirupa.com/t/populate-combobox/6965/8 "2002-10-23T03:45:59Z")

</div>

Can I have more then 2 values in my txt file.  
Like, label | data | more data.

Thanks
