There is an array collection having each item like : {device:"Abcd1", severity:"355", stupidity:"0"}. There are 3 comboboxes and we need to provide dataprovider to each of them. Obviously we want each of them to have unique value only.
There are two solutions. One is useful when array collection is continuously updated or updates very frequently. In that case we need to write a event handler for Collection Change event and then need to update the data-provider of each combo box. Another situation is array collection doesn't change quite frequently, so we define the data provider only once. I am providing solution for second situation.
//<-----ActionScript code is like------->
// three providers for combo boxes.
var
comboListOne:Array = new Array();
var
comboListTwo:Array = new Array();
var
comboListThree:Array = new Array();
// Sample
Array Collection
public var alarmsList:ArrayCollection =new ArrayCollection([
{device:"Abcd1", severity:"355", stupidity:"0"},
{device:"Abcd2", severity:"250", stupidity:"1"},
{device:"Abcd3", severity:"555", stupidity:"0"},
{device:"Abcd4", severity:"211", stupidity:"3"},
{device:"Abcd4", severity:"250", stupidity:"4"},
{device:"Abcd4", severity:"351", stupidity:"5"},
{device:"Abcd4", severity:"371", stupidity:"6"},
{device:"Abcd4", severity:"521", stupidity:"7"},
{device:"Abcd4", severity:"211", stupidity:"0"},
{device:"Abcd4", severity:"351", stupidity:"1"},
{device:"Abcd3", severity:"555", stupidity:"2"},
{device:"Abcd4", severity:"211", stupidity:"3"},
]);
//
Main function to populate.
public function
populateComboBoxDataProvider(arrayDataCopy:Array):void{
var deviceArrayHashMap:Object = new Object();
var len:uint = arrayDataCopy.length;
for(var i:int = 0; i<len; i++){
if(deviceArrayHashMap[arrayDataCopy[i].device] == undefined){
deviceArrayHashMap[arrayDataCopy[i].device] = new Object();
comboListOne.push(arrayDataCopy[i].device);
}
if(deviceArrayHashMap[arrayDataCopy[i].severity] == undefined){
deviceArrayHashMap[arrayDataCopy[i].severity] = new Object();
comboListTwo.push(arrayDataCopy[i].severity);
}
if(deviceArrayHashMap[arrayDataCopy[i].stupidity] == undefined){
deviceArrayHashMap[arrayDataCopy[i].stupidity] = new Object();
comboListThree.push(arrayDataCopy[i].stupidity);
}
}
comboListOne.sort();
comboListOne.unshift("All");
comboListTwo.sort();
comboListTwo.unshift("All");
comboListThree.sort();
comboListThree.unshift("All");
}
// These three arrays can be provided as dataprovider for the
three comboboxes. :)
+