PDA

View Full Version : getting an array into listbox component...


barrowman
10-28-2002, 11:33 AM
HIi

I know how to get an external txt file into the listbox component...

myData = new LoadVars ();
myData.onLoad = AddItems;
myData.load ("ComboBox_Text_Link2.txt");
//----------------------

function AddItems() {

for (i=0; i<5; i++) {
var Name = eval("myData.Name"+i);

var DataProvider = { Link:Name};
dropDown.addItem(Name, DataProvider);
}
dropDown.setChangeHandler("SelectItem");
}



But what if I have an array

dArray = ["item0" , "item1" , "item2" , "item3" , "item4"];

How could I get that into the component list box...

thanks in advance...

pom
10-28-2002, 11:49 AM
If your listbox is called myList, then dArray = ["item0" , "item1" , "item2" , "item3" , "item4"];
for (var item in dArray) myList.addItem(dArray[item]);will fill it. Then you can fill it on (press) or anything else...

pom :cool:

barrowman
10-28-2002, 03:36 PM
Here is what I've narrowed it down to...

dArray = ["item0" , "item1" , "item2" , "item3" , "item4"];

function AddItems() {
for (i=0; i<5; i++) {
dropDown.setDataProvider(dArray);
}
dropDown.setChangeHandler("SelectItem");
}

function SelectItem(){
trace (dropDown.getSelectedItem().dArray[1]); // this should return the same value as the drop down selected
}

But I want it to be able to trace the value via the select item...

CyanBlue
10-28-2002, 03:49 PM
Howdy... :)

Haven't tried DataProvider myself... But I know that pom's code work... That's how I have used to populate the listbox before...

barrowman
10-28-2002, 03:56 PM
thanks but I'm not entirely sure how to implement that code with the rest of it. ie how I could trace what happens when I select something...

CyanBlue
10-28-2002, 04:00 PM
dArray = ["item0" , "item1" , "item2" , "item3" , "item4"];

function AddItems()
{
for (i=0; i<5; i++)
{
dropDown.addItem(dArray[i]);
}
dropDown.setChangeHandler("SelectItem");
}

function SelectItem()
{
trace (dropDown.getSelectedItem().label);
}Try this and see if it works... :)

barrowman
10-28-2002, 04:13 PM
no doesn't seem to be loading the array into dropDown...??? :-(

CyanBlue
10-28-2002, 04:18 PM
Oh... I see what's missing... :)

Put

AddItems();

at the end of the code, and drag the listbox from the component library and name it 'dropDown'... I just tested it and it worked just fine... :)

barrowman
10-28-2002, 04:30 PM
wow, thanks so much, I don't know what I'd do without you guys. I've sent you a PM