I set caret to false.  Now the outline doesn't show, but it should 
jump to the next enabled item.  The selection disappears, but I know 
the selection is on the disabled item.  In the finishKeySelection 
function, it sets the selectedIndex to the next enabled item, but it 
seems the combobox is not accepting that.  Of course it works if you 
just have a list box.

--- In [email protected], Alex Harui <[EMAIL PROTECTED]> wrote:
>
> Try forcing caret to false when calling super
> 
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On Behalf Of wwwpl
> Sent: Thursday, August 28, 2008 9:49 AM
> To: [email protected]
> Subject: [flexcoders] ComboBox Disable Drop Down Items
> 
> 
> I am trying to disable ComboBox drop down items. I found an example
> on Alex's site for disabling items in a List so I took that and set
> it as the DropDownFactory in the combo box. But it doesn't work
> completely. I can still key down and get an outline of the disabled
> item. I am curious why this example works in a list but not in a
> combo box. Here is my code:
> 
> Application File
> >>>>>>>>>>>>>>>>>>>>>>>>>>>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> xmlns:local="*" layout="absolute">
> <mx:Script>
> <![CDATA[
> 
> [Bindable]
> public var dp:Array = [
> { label: "Category (17)" },
> { label: " Alpha (0)" },
> { label: " Beta" },
> { label: "Category (0)" },
> { label: " Delta" },
> { label: " Gamma" },
> { label: " Epsilon" }
> ];
> 
> private function noCollections(data:Object):Boolean
> {
> if (data.label.indexOf("(0)") != -1)
> return true;
> return false;
> }
> 
> ]]>
> </mx:Script>
> <mx:ComboBox dropdownFactory="DisabledItemsList" 
dataProvider="{dp}"/>
> <local:DisabledItemsList dataProvider="{dp}"/>
> </mx:Application>
> 
> DisabledItemsList.as
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> 
> package
> {
> import flash.events.MouseEvent;
> import flash.ui.Keyboard;
> 
> import mx.controls.List;
> import mx.controls.listClasses.IListItemRenderer;
> 
> /**
> * A List that uses a disableFunction to determine if an item can be
> selected or not
> */
> public class DisabledItemsList extends List
> {
> public function DisabledItemsList()
> {
> super();
> }
> 
> private function disabledFunction(data:Object):Boolean
> {
> if (data.label.indexOf("(0)") != -1)
> return true;
> return false;
> }
> 
> /**
> * The function to apply that determines if the item
> is "disabled" or not.
> * Takes one argument, which is the data item
> * Returns true if item cannot be selected.
> */
> // public var disabledFunction:Function;
> 
> override protected function drawItem(item:IListItemRenderer,
> selected:Boolean=false, highlighted:Boolean=false,
> caret:Boolean=false, transition:Boolean=false):void
> {
> if(disabledFunction(item.data))
> {
> item.enabled = false;
> selected = false;
> highlighted = false;
> }
> super.drawItem(item, selected, highlighted, caret, transition);
> }
> 
> override protected function mouseEventToItemRenderer
> (event:MouseEvent):IListItemRenderer
> {
> var listItem:IListItemRenderer =
> super.mouseEventToItemRenderer(event);
> if (listItem)
> {
> if (listItem.data)
> {
> if (disabledFunction(listItem.data))
> {
> return null;
> }
> }
> }
> return listItem;
> }
> 
> private var selectionUpward:Boolean;
> 
> override protected function moveSelectionVertically(code:uint,
> shiftKey:Boolean,
> ctrlKey:Boolean):void
> {
> if (code == Keyboard.DOWN)
> selectionUpward = false;
> else
> selectionUpward = true;
> super.moveSelectionVertically(code, shiftKey,
> ctrlKey);
> }
> 
> override protected function finishKeySelection():void
> {
> super.finishKeySelection();
> 
> var i:int;
> var uid:String;
> var rowCount:int = listItems.length;
> var partialRow:int = (rowInfo[rowCount-1].y + rowInfo
> [rowCount-1].height >
> listContent.height) ? 1 : 0;
> 
> var listItem:IListItemRenderer;
> listItem = listItems[caretIndex - verticalScrollPosition][0];
> if (listItem)
> {
> if (listItem.data);
> {
> if (disabledFunction(listItem.data))
> {
> // find another visible item
> that is enabled
> // assumes there is one that
> is fully visible
> rowCount = rowCount -
> partialRow;
> var idx:int = caretIndex -
> verticalScrollPosition;
> if (selectionUpward)
> {
> // look up;
> for (i = idx - 1; i
> >= 0; i--)
> {
> listItem =
> listItems[i][0];
> if (!
> disabledFunction(listItem.data))
> {
> 
> selectedIndex = i - verticalScrollPosition;
> 
> return;
> }
> }
> for (i = idx + 1; i <
> rowCount; i++)
> {
> listItem =
> listItems[i][0];
> if (!
> disabledFunction(listItem.data))
> {
> 
> selectedIndex = i - verticalScrollPosition;
> 
> return;
> }
> }
> }
> else
> {
> // look down;
> for (i = idx + 1; i <
> rowCount; i++)
> {
> listItem =
> listItems[i][0];
> if (!
> disabledFunction(listItem.data))
> {
> 
> selectedIndex = i - verticalScrollPosition;
> 
> return;
> }
> }
> for (i = idx - 1; i
> >= 0; i--)
> {
> listItem =
> listItems[i][0];
> if (!
> disabledFunction(listItem.data))
> {
> 
> selectedIndex = i - verticalScrollPosition;
> 
> return;
> }
> }
> }
> }
> }
> }
> }
> }
> 
> }
>


Reply via email to