Create a new AS 3.0 fla
Add a List component to the stage - name it “theList”
In the parameters panel, add 4 (or more) items.
Paste the code below in the actions panel:
import fl.controls.List;
import flash.events.Event;
import fl.accessibility.ListAccImpl;
ListAccImpl.enableAccessibility();
// I expected this line
theList.selectedItem = theList.getItemAt(2);
// or this line, to set the internal index to 2
theList.selectedIndex = 2;
theList.setFocus();
theList.addEventListener(Event.CHANGE, onListChange);
function onListChange(e:Event)
{
trace("You have clicked: " + theList.selectedItem.label + " in row " + theList.selectedIndex);
}
stop();
Run it.
The 3rd item (index 2) appears selected in the UI - all seems well.
Press the down arrow to go to the 4th item in the list. Oops, what happened?
Expect:
4th item (index 3) is selected.
Actual:
1st item (index 0) is selected.
Internally, it seems, the object thinks it’s index is still -1 when the Keyboard event arrives.
So, how do you make sure that not only the UI looks correct, but internally, the component remembers it’s selected index?
thanks,
Mark