Avg. Rating 3.0

Problem

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.

Solution

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.

Detailed explanation

//<-----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. :)
 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes