Question

I would like to print the values of my associative array in a list. Im doing this, but i think the IList class uses the common index [0]..[n] to print the elements (im not sure of this)

my code(example):

private var arr = new Array();
private var arrList: new ArrayList(arr);


private function init()
{
  arr["hello"]="world";
  list.dataProvider = arrList; //the component was instanced before
}

I have been debbugging and the arrList updates the info with elements of arr, but list component dont show anything.

Any suggestion? Thanks.

Was it helpful?

Solution

dataProvider appears to accept key:value pairs as label and data object entries pushed to an array which is mirrored the actual List. Personally, I prefer to roll with my own list class, so I'm not speaking from List object experience. See Adobe's documentation for List.dataProvider for more info.

private var foo:Object = {
    "hello":"world",
    "apple":"pie",
    "orange":"juice"
}

var dpArr:Array = [];
list.dataProvider = dpArr;

for (var key:String in foo) {
    dpArr.addItem({label:key, data:foo[key]});
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top