Flex 2.0.1 ComboBox with icon support.
April 28, 2007
Sometimes a ComboBox with icons in the list as well as in the text display area can be useful. However the out of the box Flex ComboBox component dosn’t support this. Here is one way of doing it.
![]()
Basically I’ve extended the existing ComboBox adding iconField and iconFunction properties. I had to instance my own ClassFactory for the internal list that is used as the dropdown so that I could pre-initialize the required properties. I override the measuredWidth so that I can make room for the icon, and adjust the x position of the internal textInput to compensate.
A little addition to the toolbox that can come in really handy.
Sample and Source : IconComboBox
Enjoy.
Jason Hawryluk
April 29, 2007 at 5:22 pm
When I click view source and it goes to delicious. what’s happening?
April 29, 2007 at 6:50 pm
Seems to be working fine here? Weird.
Anyone else having trouble ?
jason
May 7, 2007 at 3:23 pm
View Source appears to be working fine here. Thanks for the code!
July 5, 2007 at 2:27 pm
[...] Flex 2.0.1 ComboBox with icon support. « Flexible Experiments [...]
August 4, 2007 at 5:08 pm
Source link seems to be not working
August 4, 2007 at 5:19 pm
Seems to be working for me.
Ben, try again, and let me know.
Jason
October 19, 2007 at 9:00 am
Do you have embed the icons? I need to load them dynamically. But it keeps throwing an error in measuredWidth (null object reference)
…
var l:String = element.@nld+” - “+element.@nom;
var ic:String = “images/flags/”+String(element.@nld).toLowerCase()+”.png”; trace(ic);
countryArr[cntr] = {label:l, data:ic};
…
…
November 7, 2007 at 6:11 am
Thanks, very useful
November 9, 2007 at 7:25 am
[...] was off to Google to see if anyone had done this previously. We found this great post on the blog Flexible Experiments explaining how you can create a combo box which supports icons. Of course our designers [...]
November 28, 2007 at 6:33 pm
Viewing source code seems to work OK.
January 25, 2008 at 2:11 am
Jason, this is a terrific piece of code. Do you know if it would be simple to extend the icon to contain an object drawn in Flex as opposed to an image?
February 26, 2008 at 6:20 pm
Hey Jason,
great job! It will be very useful at my project (Teeth chart).
Excellent!
April 29, 2008 at 1:35 pm
Jason,
Thanks for the code. Not specifying icon however throws an error at creation. Your measureWidth shoulb changed to sg like that:
override public function set measuredWidth(value:Number):void
{
if (displayIconObject == null)
super.measuredWidth = value + getStyle(”cornerRadius”);
else
super.measuredWidth = value + (DisplayObject(displayIconObject).width+getStyle(”cornerRadius”));
}