View Full Version : changing style of selected item in a list

07-13-2006, 03:14 PM
I'd like to change the fontcolor of a selected item in a list (ie. you click on the list item and it changes colors or font weight).

Here is my partical mxml which does not work:
private function answerSelected(even:flash.events.Event):void {
event.target.selectedItem.setStyle("fontColor", "red");

<mx:List id="answers" dataProvider="{myCollection"} change="answerSelected" />

I've been struggling with these for 2 days...you're help is appreciated.


07-19-2006, 09:30 AM
event.target.selectedItem.setStyle("fontColor", 0xFF0000);

07-19-2006, 11:08 AM
I think you'd get an error on that as the event.target will return a DisplayObject, and these don't have a 'selectedItem' prop. You just need to cast it first.

var myList:List = List(event.target);
myList.selectedItem.setStyle("fontColor", 0xFF0000);