In AS2, there was a style named textSelectedColor that would allow you to set the text color of the text of a selected item in a list-based component. In Flash CS 3, it appears to have been removed, which means (unless I totally missed something obvious...if I did, please let me know) that you need to create a CellRenderer and let it set the TextFormat of the label based on whether it is selected or not.
CellRenderers have a property called selected to let them know if their particular row is selected. CellRenderers also have access to any custom properties of it's class. So what I wound up doing was overriding the drawTextFormat() method (which CellRenderer inherits from LabelButton), checking the value of the selected property, and if it's true, use a custom selectedTextFormat property of the CellRenderer to format the text.
Looking at the code will propbably be a bit clearer, it's very simple:
-
package {
-
-
import fl.controls.listClasses.CellRenderer;
-
import fl.controls.listClasses.ICellRenderer;
-
import fl.core.UIComponent;
-
import flash.text.TextFormat;
-
-
-
public class SelectedItemCellRenderer extends CellRenderer {
-
-
private var selectedTextFormat:TextFormat;
-
-
public function SelectedItemCellRenderer(){
-
super();
-
-
selectedTextFormat = new TextFormat();
-
selectedTextFormat.font = 'Verdana';
-
selectedTextFormat.size = '12';
-
selectedTextFormat.color = 0xFFFFFF;
-
}
-
-
override protected function drawTextFormat():void {
-
// Apply a default textformat
-
var uiStyles:Object = UIComponent.getStyleDefinition();
-
var defaultTF:TextFormat = enabled ? uiStyles.defaultTextFormat as TextFormat : uiStyles.defaultDisabledTextFormat as TextFormat;
-
textField.setTextFormat(defaultTF);
-
-
var tf:TextFormat = getStyleValue(enabled?"textFormat":"disabledTextFormat") as TextFormat;
-
-
if(selected){
-
tf = selectedTextFormat;
-
}
-
-
if (tf != null) {
-
textField.setTextFormat(tf);
-
} else {
-
tf = defaultTF;
-
}
-
textField.defaultTextFormat = tf;
-
-
setEmbedFont();
-
}
-
-
-
}
-
-
}
As far as the Flex components, they still have the textSelectedColor property.
Thank you very, very much, you have saved my weekend!