View Full Version : Components, comboBox, retrieving data from a txt
eggnogg
04-03-2003, 01:15 PM
i got a comboBox with 5 items. is there a way to set the data for thoose 5 item, from an external txt file? using variables maybe..
logicaly thinking i'd do:
txt file
======
&a=10&
Fla file
======
FRAME ACTION : loadVariablesNum("price.txt", 0);
comboBox.item1.data = a
but unfortunately actionscritp isnt writen based on logical phrases!!
can anybody give a hand on this please?
thumbs up fror actionscript.org
freddycodes
04-03-2003, 03:00 PM
You'll want to use LoadVars and the onData event handler. Then you can split the results on a newline and loop through them adding them to an array, and use the setDataProvider method of the comboBox to load the values and labels.
The text file
a|10
b|20
c|30
d|40
The actionscript.
tmpArr = [];
myVars = new LoadVars();
myVars.load("combo.txt");
myVars.onData = function(raw) {
tmp = raw.split("\n");
for(var i=0;i<tmp.length;i++) {
tmp2 = tmp[i].split("|");
tmpArr.push({data:tmp2[0], label:tmp2[1]});
}
myCombo.setDataProvider(tmpArr);
}
eggnogg
04-03-2003, 03:22 PM
ok..thx freddy. :)
gonna try it out and see what happens ;)
eggnogg
04-03-2003, 04:15 PM
is there anyway of doing this without creating the array?
isn't there a more simple way ?!
thx
eggnogg
freddycodes
04-03-2003, 04:19 PM
Yes but if you wanted to reuse the data from the text file you would need to reload it. Was there something particularly diffcult about that code? I thought it was pretty easy if you ask me.
myVars = new LoadVars();
myVars.load("combo.txt");
myVars.onData = function(raw) {
tmp = raw.split("\n");
for(var i=0;i<tmp.length;i++) {
tmp2 = tmp[i].split("|");
myCombo.addItemAt(i, tmp2[0], tmp2[1]);
}
}
eggnogg
04-03-2003, 04:57 PM
The thing is i dont understand half the script yet! :p :)...i was hoping that there would be a simple way to load the data...
i actually dont need to reuse it..i mean...the swf opens and retrievs the info in the txt only once so i dont think ill need to reuse the txt info...
freddycodes
04-03-2003, 05:02 PM
Thats pretty darned simple
//Create a new instance of the LoadVars object
myVars = new LoadVars();
//Load the text file
myVars.load("combo.txt");
//Run this when the data has loaded
myVars.onData = function(raw) {
//Split the loaded text into an array by newline
tmp = raw.split("\n");
//Loop through the array
for(var i=0;i<tmp.length;i++) {
//make a new array from each element of the first array splitting on the | symbol
tmp2 = tmp[i].split("|");
//Add an item to the comboBox for this element of the text file
myCombo.addItemAt(i, tmp2[0], tmp2[1]);
}
}
eggnogg
04-16-2003, 02:28 PM
yo
how should the data in txt file be formatted??
i need to set a label and a value associated to the label (comboBox)
eggnogg
freddycodes
04-16-2003, 06:55 PM
Count 7 posts up from this one, I showed you the format for the text file in there, the data on the left of the | and the label on the right.
Check the attached file
|
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.