1 Reply Latest reply on Mar 31, 2010 3:04 PM by JPAntona

    getting selected item from a mx.controls.List


      I have events defined on a mc.controls.List object, specifically:

      // set the event handlers theText.addEventListener(KeyboardEvent.KEY_UP,getSuggestions);                 theList.addEventListener(KeyboardEvent.KEY_UP, setKeyInput); theList.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, setListInput);


      When any of these events trigger, I funnel the execution to a function called setInput(). Specifically:


      private function setKeyInput(evt:KeyboardEvent):void {                if ( evt.keyCode == Keyboard.ENTER ) {                     setInput(evt);                     } else if ( evt.keyCode == Keyboard.ESCAPE) {                     hideList();                }           }                      private function setMouseInput(evt:MouseEvent):void {                setInput(evt);           }                      private function setListInput(evt:ListEvent):void {                setInput(evt);           }                      private function setFocusInput(evt:FocusEvent):void {                setInput(evt);           }                      private function setInput(evt:Event):void {                var theText:TextInput = TextInput(getChildAt(0));                var theList:List = List(getChildAt(1));                //var theList:List = List(evt.currentTarget);                var osel:Object = theList.selectedItem;                                var isel:int = theList.selectedIndex;                //Alert.show("setInput " + isel);                Alert.show("setInput " + theList.selectedItem.label.toString());                                theText.text = theList.selectedItem.data;                this.text = theText.text;                this.value = XML(theList.selectedItem).data;                hideList();           }


      The context for all of this code is an ActionScript class definition.


      So the problem here is that, no matter what I do, I cannot retrieve the selected value from the List. The selectedIndex value is correct, but I can't get anything out of the List.selectedItem property. I think it might be a lifecycle thing because my events may occur before the list commit value event, but I don't see how I can register the commitValue event to trigger for these functions.


      Basically, how to I get a handle on the selectedItem?