Hello All,
I have an interesting issue with selection and user interaction with a
listbox.  We have a situation where the items in a list box represent
a set of data that is also available in another component on the
stage.  If the user selects an item, either in the listbox or in the
other component, the item is placed at the top of the listbox, the
rest of the data is ordered below the first item and the first item is
then selected.

This functionality is working perfectly when I have 3 or more items to
select from, but when there are only 2 items in the list the selection
behavior goes awry. With 2 items in the list, and the second item is
then selected by the user, the selected item correctly becomes the
first item and is visually selected but once this occurs you can no
longer select the second item via the mouse until you click on the
first item.  Once you click on the first item the list behaves as
expected until you select the second item and you are then back in the
same state.  Here is the code to reproduce the issue:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" creationComplete="init()">
        <mx:Script>
                <![CDATA[
                        import mx.collections.ArrayCollection;                  
                        
                        [Bindable] public var dp:ArrayCollection;
                        public var source:ArrayCollection;
                        
                        public function init():void
                        {
                                dp = source = new ArrayCollection([{label: 
"item 1", data: 1},
{label: "item 2", data: 2}]);
                        }
                        
                        public function handleChange(event:Event):void
                        {
                                var data:Object = event.target.selectedItem;
                                var list:ArrayCollection = new 
ArrayCollection([data]);
                                for each(var item:Object in source)
                                {
                                        if(item != data)
                                        {
                                                list.addItem(item);
                                        }
                                }
                                dp = list;
                                myList.selectedIndex = 0; 
                        }
                        
                ]]>
        </mx:Script>
        <mx:List x="10" y="10" id="myList" dataProvider="{dp}" width="200"
change="handleChange(event)"></mx:List> 
</mx:Application>

I have tried different approaches, from enabling to disabling, using
callLater(), etc. but it always ignores the mouse event.  I have also
tried adding a "blank" item {label: "", data: 3} and this does not fix
it either, nor is this really a valid option for me.  Any ideas?

Thanks,
James

Reply via email to