PDA

View Full Version : fl.controls.List: bug or user error?



markkra
June 16th, 2007, 07:13 PM
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

dthought
June 18th, 2007, 08:43 AM
Without knowing too much about components, I've had a look at how that code behaves and it appears to be getting a little confused with its caretIndex, inherited from the SelectableList... I'm not sure why, or how to dig inside it (the debugger doesn't like to play with breakpoints inside these classes), but my thoughts are that you may have stumbled onto an issue...

It could be... humm... a scope issue, perhaps. There's a lot of sticky (as in, difficult to mentally disentangle) work between those two classes - lots of overrides and protected methods and properties that are shared. Tricky to debug... but yeah, you may have found something.

markkra
June 20th, 2007, 05:29 PM
Yup, setting the selectedIndex or selectedIndices just takes care of the _selectedIndices array and doesn't do anything for the caretIndex as far as I can tell. Looks to me like the keyboard handling is all based off caretIndex. So, calling selectedIndex gets them out of sync.