Loading items from a text file into a listbox

As the title suggest I am wondering how do you load the contents of a text file into a listbox component. My text file is formatted like this.

item1
item2
item3


Thx in advance…

well, although i’ve never used a component, i assume it would be something like this:

var myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success) {
	if (success) {
		var contents = this.contents.split(","), index;
		for (index=0; index<contents.length; index++) {
			myFListBox.addItem(contents[index]);
		}
	} else {
		trace("error loading contents");
	}
};
myLoadVars.load("contents.txt");

and your .txt file should read:

contents=item1,item2,item3,item4&amp;

hope it helps… :stuck_out_tongue: :wink:

Kax

thx for the help. Only problem I have is the formatting of the text file has to stay as it is (one item per line) so is there any way that your code could be modded for that ?

ehmm… try this:

var myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success) {
	if (success) {
		var contents = unescape(this).split("
"), index;
		for (index=0; index<contents.length; index++) {
			myFListBox.addItem(contents[index]);
		}
	} else {
		trace("error loading contents");
	}
};
myLoadVars.load("contents.txt");
ASSetPropFlags(myLoadVars, "onLoad", 1);

:-\

wait… now that i think about it, there will be an assignment operator (=****) in the last item, try this instead:

var myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success) {
	if (success) {
		var str = unescape(this), contents = str.substr(0, str.length-1).split("
"), index;
		for (index=0; index<contents.length; index++) {
			myFListBox.addItem(contents[index]);
		}
	} else {
		trace("error loading contents");
	}
};
myLoadVars.load("contents.txt");
ASSetPropFlags(myLoadVars, "onLoad", 1);

were getting there…

One last problem is if the item has an ampersand character in it then the list gets messed up so how would I escape the “&” character so the formatting stays as it is in the text file and thx again for the help.

%26 :wink:

thanks again for the help and I am sure your asking yourself “can’t this guy do anything for himself” but I was wondering if there was a way to escape the “&” from within the code and not in the text file itself ?

If not or it would be too difficult to code then I understand and thanks alot again.

you’re welcome. :wink:

and no, i don’t think so (at least i can’t think of anything right now), you’ll have to escape the ampersand in the .txt file. :-\

What kind of title is that, kax?
you’re

Sen.removeListener(pom);

'ing me?
:trout:
That’s for you

function ClearKax (clip){
for (var i in clip){
if (typeof (clip*) == Kax) delete clip*;
else ClearKax(clip*);
}
}
ClearKax(_root);

:evil:

what kind of title is that, ilyas!? :hair:

senocular is mine and only mine!! :trout:

No!!! :frowning:

ehem… you edited your post… :stuck_out_tongue:

and yes!! he’s mine!! :bad: