Archive for the ‘Combo Box’ Category

Action script Date Data Provider

June 18, 2010 3 comments

I had a requirement to show 2 drop downs for From and To selection of months and year, values like this:

Jan, 2010
Feb, 2010 and so on

And I used the following class to get this working like this.

Based on the class from

public function getListOfMonthsAndYear(date:Date,noOfMonths:int = 12):ArrayCollection
var monthArr:ArrayCollection = new ArrayCollection();
var obj:Object = new Object();
var dt:Date = new Date();
//Fixed it on the basis of Matt’s comments, see below – comment section (Thx Matt)
// This because the above utility can’t handle 31 days, so forcing it to start of the day
date = new Date(date.getFullYear(),date.getMonth(),1);
dt = new Date(dt.getFullYear(),dt.getMonth(),1);
var n:int = 0;
for (var i:int = noOfMonths; i >= 0; i–)
dt = DateUtils.dateAdd(DateUtils.MONTH,-i, date);
obj = new Object();
obj[‘label’] = DateUtils.dateFormat(dt,’MMM YYYY’);
obj[‘data’] = DateUtils.dateFormat(dt,’YYYYMM’);
obj[‘no’] = n;
return monthArr;

Then I created filtering on the second drop down to remove all the entries which are not relevent, like if you select in your From combo, say Month March, 2010 then you don’t want user to select Jan, 2010 in To combo as that would be wrong.

Here is the filter I created on Array Collection:

* From Month Change Handler
private function onFromMonthChange(event:Event):void
var comboBox:ComboBox = null;

comboBox = event.currentTarget as ComboBox;
this.currFromMonthNo = Number( );
this.monthToDP.filterFunction = this.toMonthFilter;
if (this.monthToDP.length > 0) this.monthsTo.selectedIndex = 0;
this.criteria.monthFrom =;
this.criteria.monthTo =;

private function toMonthFilter(obj:Object):Boolean
return Number( >= this.currFromMonthNo;

Actually I used a trick to store number starting from 1 to end of the list in both collections and removed the items with the no’s above the selected one from To combo list


Categories: ActionScript, Adobe, Combo Box, Flex

Adobe Flex Combo box Binding Bug

June 18, 2010 Leave a comment

I was working on one project at 2nd Byte and hit this problem of Combo Box’s data provider not being updated intermittently.

I came across one post which described the bug in SDK 3.5 (it was in previous SDK’s as well.

I was doing like this:
[Bindable] public var comboDP:ArrayCollection;

myComboBox.dataProvider = comboDP;

and this wasn’t getting updated values and had to do like this to get this working:

myComboBox.dropdown.dataProvider = comboDP;

Link to the post


Categories: Adobe, Combo Box, Flex, Flex SDK