<mx:ColorPicker id="colorPicker" change="onColorPickerChange(event)" enter="onColorPickerEnter(event)"/>
/** 選取顏色觸發 **/
private function onColorPickerChange(event:ColorPickerEvent):void {
var color:uint = event.currentTarget.selectedItem as uint;
var colorHex:String = StringUtils.intToHexColor(color);
this.setStyle("backgroundColor", colorHex);
}
/** 輸入顏色值按 Enter 觸發 **/
private function onColorPickerEnter(event:ColorPickerEvent):void {
var colorHex:String = StringUtils.intToHexColor(event.color);
this.setStyle("backgroundColor", colorHex);
}
/** 將 int 轉為 #FFFFFF 顏色字串格式 **/
public static function intToHexColor(value:uint):String
{
var mask:String = '000000';
var str:String = mask + value.toString(16).toUpperCase();
return '#' + str.substr(str.length - 6);
}
2008/10/08
Flex Color Picker 範例
訂閱:
文章 (Atom)