User Guide

ComboBox.dataProvider 177
The List component, like other data-aware components, adds methods to the Array object’s
prototype so that they conform to the DataProvider API (see DataProvider.as for details).
Therefore, any array that exists at the same time as a list automatically has all the methods
(
addItem(), getItemAt(), and so on) needed for it to be the model of a list, and can be used
to broadcast model changes to multiple components.
If the array contains objects, the
labelField or labelFunction property is accessed to
determine what parts of the item to display. The default value is
"label", so if such a field
exists, it is chosen for display; if not, a comma-separated list of all fields is displayed.
Any instance that implements the DataProvider API is eligible as a data provider for a List
component. This includes Flash Remoting RecordSet objects, Firefly DataSet components,
and so on.
Example
This example uses an array of strings to populate the drop-down list for the ComboBox
component instance
my_cb:
my_cb.dataProvider = [{data:1, label:"First Item"}, {data:2, label:"Second
Item"}];
/* is the same as
my_cb.addItem({data:1, label:"First Item"});
my_cb.addItem({data:2, label:"Second Item"});
*/
This example creates a data provider array and assigns it to the
dataProvider property:
var myDP:Array = new Array();
list.dataProvider = myDP;
for (var i:Number = 0; i < accounts.length; i++) {
// These changes to the DataProvider will be broadcast to the list.
myDP.addItem({label: accounts[i].name,
data: accounts[i].accountID});
}
NOTE
If the array contains strings at each index, and not objects, the list is not able to sort the
items and maintain the selection state. Any sorting causes the selection to be lost.