Search code examples
apache-flexlistflex4mxmlunselect

Flex 4 - Select & Deselect same item in <s:List> with a mousedown


In Flex 4, I have a Spark List component with item renderers. I would like to select an item in the List by clicking on it, and deselect it also, by clicking on the same selected item. Like an on/off switch.

My item renderer has the following states:

<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>

so I tried to add a click event listener to the item renderer with:

private function selectUnSelect():void {
if (currentState == 'selected') currentState = 'normal';
else currentState = 'selected';

}

with an awkward behaviour... where the item stay selected even after clicking it again in the selected state.

Think of using the List component without the Command (on mac) or the Control button on windows.


Solution

  • This blog post might be useful to you: http://flexponential.com/2009/12/13/multiple-selection-in-a-spark-list-without-the-control-key/