ListBox and TXT Files

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 …

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;

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 … ?!?

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 …

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



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.

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 …

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


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…


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;
}
		

}

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

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

thx.

:slight_smile:

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

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