hmmmm it seems the listsrv ate my file. :-( here, I'll paste it in. And BTW: it is for spark.
package spark.components { import flash.events.Event; import mx.collections.ArrayCollection; import mx.collections.IList; import mx.events.CollectionEvent; public class EmptyItemComboBox extends ComboBox { protected var _emptyItem:Object = new Object(); protected var _originalDataProvider:IList = null; private var _enableEmptyItem:Boolean = true; private var _emptyItemValue:* = -1; private var _emptyItemLabel:String = ""; public function EmptyItemComboBox() { super(); _emptyItem.label = _emptyItemLabel; _emptyItem.value = _emptyItemValue; addEmptyItem(); addEventListener(Event.CHANGE, onChange); } private function onChange(event:Event):void { dispatchEvent(new Event("isEmptySelectedChanged")); } [Bindable] public function get emptyItem():Object { return _emptyItem; } public function set emptyItem(value:Object):void { if (_emptyItem != value) { clearEmptyItem(); _emptyItem = value; addEmptyItem(); } } [Bindable(event="isEmptySelectedChanged")] public function get isEmptySelected():Boolean { return (selectedItem == null || (_emptyItem != null && selectedItem == _emptyItem)); } override public function set selectedItem(value:*):void { if (value == null && emptyItem != null) { super.selectedItem = emptyItem; } else if (value != selectedItem) { super.selectedItem = value; } dispatchEvent(new Event("isEmptySelectedChanged")); } override public function set dataProvider(value:IList):void { if (_originalDataProvider != null) { _originalDataProvider.removeEventListener( CollectionEvent.COLLECTION_CHANGE, onOriginalCollectionChange); } super.dataProvider = value; _originalDataProvider = (dataProvider as IList); if(value) { _originalDataProvider.addEventListener( CollectionEvent.COLLECTION_CHANGE, onOriginalCollectionChange ); if(_enableEmptyItem) { addEmptyItem(); } } } private function clearEmptyItem():void { if (emptyItem != null && dataProvider != null && dataProvider is IList) { var dp:IList = dataProvider as IList; var idx:int = dp.getItemIndex(_emptyItem); if (idx >=0) { dp.removeItemAt(idx); } } dispatchEvent(new Event("isEmptySelectedChanged")); } private function addEmptyItem():void { if(_enableEmptyItem) { if (emptyItem != null) { if (dataProvider != null && dataProvider is IList && dataProvider.length) { var dp:IList = dataProvider as IList; var idx:int = dp.getItemIndex(_emptyItem); if (idx == -1) { var newDp:ArrayCollection = new ArrayCollection(dp.toArray().concat()); newDp.addItemAt(_emptyItem, 0); super.dataProvider = newDp; typicalItem = newDp.getItemAt(1); } } } } dispatchEvent(new Event("isEmptySelectedChanged")); } private function onOriginalCollectionChange(event:CollectionEvent):void { if (_emptyItem != null) { dataProvider = _originalDataProvider; addEmptyItem(); } } override protected function commitProperties():void { try { super.commitProperties(); } catch(dirtyFix:Error) { trace("AIIIIIII KERNEL PANIC!!! FIX ME!!!!!!!!!!!!!!!!!!!"); } } public function get enableEmptyItem():Boolean { return _enableEmptyItem; } public function set enableEmptyItem(value:Boolean):void { _enableEmptyItem = value; } public function get emptyItemValue():* { return _emptyItemValue; } public function set emptyItemValue(value:*):void { _emptyItemValue = value; _emptyItem.value = value; } public function get emptyItemLabel():String { return _emptyItemLabel; } public function set emptyItemLabel(value:String):void { _emptyItemLabel = value; _emptyItem.label = value; clearEmptyItem(); addEmptyItem(); // LogObj(emptyItem); } } } > Date: Tue, 10 Apr 2012 10:30:53 -0700 > Subject: Re: combo box > From: s9tpep...@apache.org > To: flex-dev@incubator.apache.org > > On Tue, Apr 10, 2012 at 10:23 AM, David Coleman < > david_coleman_...@hotmail.com> wrote: > > > Hi everyone. Mike's most recent mail (mentioning that ComboBoxes have > > changed nearly every other release) made remember something that i have had > > sitting around in my personal files for some time. It is a tweak to the > > combo box that allows you to have a blank item as the first item, allowing > > you to de-select the selected item and reset the combo to empty. It has a > > configurable value (which defaults to -1) and a configurable label to show > > in the list (in case you want it to say "choose a city" or something else > > more context appropriate). > > > > I'm attaching the file. Maybe it is something worth considering. It is a > > behavior that is definitely lacking when you compare flex to other form > > entry UI/UX approaches. The ability to "cancel" your selection in a combo > > box is rather basic and I've always been mildly surprised that it has never > > been introduced. > > > > Cheers! > > David > > > > Hi David, > > First of all welcome to the group! I don't see your file attachment, but > just wanted to ask is that for an MX component or Spark? Reason I ask is I > believe there is a prompt property on the Spark component to set a message, > or make it blank, when selectedIndex equals -1. Just throwing that out > there... > > -- > Omar Gonzalez > s9tpep...@apache.org