Is there a way to load an external txt file into a combo box.
Well of course. Why not? After all it is just text that you are entering in your combobox…
pom
Well, would you mind letting me in on your secret.=)
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:
//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
pom
I’ll be back.:asian:
My pleasure…
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
Can I have more then 2 values in my txt file.
Like, label | data | more data.
Thanks