View Full Version : How to display dynamic labels into Listbox Component?

12-18-2005, 02:24 PM

I have a php script that echo's name-value pairs, that are loaded into flash with this code:

myData = new LoadVars()
myData.ref = this
myData.onLoad = function(succes){
for(var i=0; i<this.tel; i++){
this.ref["test"+i].text = this["naam"+i]
} else trace("Error loading data")

Also I have a listbox component, called 'myList'
What I want is, that the content of this.ref["test"+i].text = this["naam"+i], is used as a label for my listbox.

For the myList I've got the following code:

// populate the list box
myList.addItem(item1); // so here i want to get the dynamic labels, but how???

myListListener = new Object();
myListListener.change = function ( eventObj )
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.label;
var theSelectedItemData = theSelectedItem.data;

myList.addEventListener ("change", myListListener);

Does anyone know how to get this working?
I would realy appreciate your feedback.


12-18-2005, 05:27 PM
I think you just want to do:
var numBoxes:Number = 5; // for 5 boxes
for (var i = 0; i < numBoxes; i++) {
myList.addItem({label: myData["test"+i].text, data:i});