[Event(name="change", type="flash.events.Event")] ; private var _selectedIndicesChanged:Boolean=false; [Bindable] public function set selectedIndices(value:Vector.):void{ _selectedIndices=value; _selectedIndicesChanged=true; invalidateProperties(); } public function get selectedIndices():Vector.{ return _selectedIndices; } [Bindable] public function set selectedItems(value:Vector.):void{ var indices:Vector.=new Vector.(); var index:int; for each(var obj:Object in value){ index=list.dataProvider.getItemIndex(obj); if(index>-1)indices.push(index); } selectedIndices=indices; } public function get selectedItems():Vector.{ return list.selectedItems; } // -------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------- public function open():void{ popUpAnchor.displayPopUp = true; list.setFocus(); callLater(addListKeyDownListener); callLater(observeMouse); } public function close():void{ popUpAnchor.displayPopUp = false; stopMouseObserve(); list.removeEventListener(KeyboardEvent.KEY_DOWN,list_keyDownHandler); } public function selectAll():void{ var indices:Vector.=new Vector.(); for(var i:uint=0;i(); } // -------------------------------------------------------------------- // // Protected Methods // // -------------------------------------------------------------------- override protected function commitProperties():void{ super.commitProperties(); if(_selectedIndicesChanged){ list.selectedIndices=_selectedIndices; _selectedIndicesChanged=false; invalidateDisplayList(); } if(_openChanged){ if(popUpAnchor.displayPopUp){ close(); }else{ open(); } _openChanged=false; } } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{ super.updateDisplayList(unscaledWidth, unscaledHeight); list.width=width; if(dataProvider)updateLabel(); } // -------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------- //spark.skins.spark.DropDownListButtonSkin doesn't contain a label, so we reparent labelDisplay there //this is less annoying than having to create a custom skin private function addLabel():void{ SparkSkin(dropDownButton.skin).addElement(labelDisplay); } private function flagOpenToggle():void{ _openChanged=true; invalidateProperties(); } private function dropDownButton_mouseDownHandler():void{ flagOpenToggle(); } private function dropDownButton_focusInHandler():void{ if(!popUpAnchor.displayPopUp){ _nextFocusItem=focusManager.getNextFocusManagerComponent(); flagOpenToggle(); } } private function list_focusInHandler(event:Event):void{ event.stopImmediatePropagation();//make sure dropDownButton_focusInHandler() isn´t called } private function addListKeyDownListener():void{ list.addEventListener(KeyboardEvent.KEY_DOWN,list_keyDownHandler); } private function list_keyDownHandler(event:KeyboardEvent):void{ if(event.charCode==Keyboard.ENTER){ flagOpenToggle(); callLater(moveToNextFocusItem); } if(event.charCode==Keyboard.TAB){ flagOpenToggle(); event.stopImmediatePropagation(); callLater(moveToNextFocusItem); } } private function moveToNextFocusItem():void{ focusManager.setFocus(_nextFocusItem); } private function list_indexChangeHandler():void{ _selectedIndices=list.selectedIndices; invalidateDisplayList(); dispatchEvent(new Event(Event.CHANGE)); } //================== //label updating //================== //because vectors don's seem to have inbuilt sort?! private function numericalSort(a:int,b:int):int{ if(a==b){ return 0; }else if(a>b){ return 1; } return -1; } private function getLabelStringFromSelectedIndices():String{ var items:Array=[]; var item:Object; _selectedIndices.sort(numericalSort); for(var i:uint=0;i<_selectedIndices.length;i++){ item=dataProvider.getItemAt(_selectedIndices[i]); if(item is String){ items.push(item); }else if(item.hasOwnProperty("label")){ items.push(item.label); } } return items.length ? items.join(", ") : selectedIndices.toString(); } private function updateLabel():void{ if(!labelDisplay)return; var string:String=prompt; if(_selectedIndices && _selectedIndices.length){ string=getLabelStringFromSelectedIndices(); } labelDisplay.text=string; } //================== //mouse observe //================== private function checkMouseOut(event:MouseEvent):void{ if(!_mouseObserveRectangle.contains(stage.mouseX,stage.mouseY))flagOpenToggle(); } private function observeMouse():void{ var point:Point=localToGlobal(new Point()); if(list.y