PDA

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


djsodom
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:
<mx:Script>
<![CDATA[
private function answerSelected(even:flash.events.Event):void {
event.target.selectedItem.setStyle("fontColor", "red");
}

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

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

Steve

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

Tink
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);