<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="CheckBox_color_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Style> // 设置样式
CheckBox {
fontWeight: bold;
iconColor: green;
}
.selectedStyle {
color: green;
textRollOverColor: green;//鼠标指针移动到按钮位置时,标签的文本颜色。
textSelectedColor: green;//鼠标指针移动到按钮位置时,标签的文本颜色。
themeColor: green;
}
.unselectedStyle {
color: red;
textRollOverColor: red;
textSelectedColor: red;
themeColor: red;
}
</mx:Style>
<mx:Script>
<![CDATA[
// 触发函数
private function checkBox_change(evt:Event):void {
var tgt:CheckBox = evt.currentTarget as CheckBox;
if (tgt.selected) // 选中时该组件的样式
{
tgt.styleName = "selectedStyle";
} else //未选中时的样式
{
tgt.styleName = "unselectedStyle";
}
}
]]>
</mx:Script>
<!-- styleName 为默认样式 selected为false是默认状态下未选中状态 change为触发事件-->
<mx:CheckBox id="checkBox"
label="CheckBox"
selected="false"
styleName="unselectedStyle"
change="checkBox_change(event);" />
</mx:Application