tags:

views:

21

answers:

1

In the following working example the list's selected index is supposed to reset to 0 whenever the text box changes.

However, for some odd reason every other keystroke the selected item disappears and then reappears at the subsequent keystroke.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayList;
            import mx.core.UIComponent;
            import mx.events.FlexEvent;

            import spark.effects.Scale;
            import spark.events.TextOperationEvent;

            [Bindable]
            public var items : ArrayList;

            protected function textinput1_changeHandler(event:TextOperationEvent):void
            {
                items = new ArrayList(input.text.split(" "));
                list.selectedIndex = 0;
            }
        ]]>
    </fx:Script>
    <s:TextInput x="165" y="124" change="textinput1_changeHandler(event)" id="input" text="a few words"/>
    <s:List x="165" y="184" width="433" height="291" dataProvider="{items}" id="list"></s:List>
</s:Application>
A: 

First you should check "String.split" function. It has several bugs, I don't remember them. Try it on sequence like " " or "blah " (space at the end).

Also you should wait until the List is actually updated. Changing the bindable property only fires some event, not actually changing the list (AFAIK). Just google List's events. Also you may try to override List's "dataProvider" setter.

Lavir the Whiolet