A ColorPicker uses an Array of Objects with three fields: color, label, and descript
<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".
This user guide is licensed for use under the terms of the Creative Commons Attribution
Non-Commercial 3.0 License.
This License allows users to copy, distribute, and transmit the user guide for noncommercial
purposes only so long as
(1) proper attribution to Adobe is given as the owner of the user guide; and
(2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms.
The best way to provide notice is to include the following link.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
-->
<!-- controls\colorpicker\CPObjects.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
import mx.events.ColorPickerEvent;
import mx.events.DropdownEvent;
[Bindable]
public var complexDPArray:Array = [
{label:"Yellow", color:"0xFFFF00", descript:"A bright, light color."},
{label:"Hot Pink", color:"0xFF66CC",descript:"It's HOT!"},
{label:"Brick Red", color:"0x990000",descript:"Goes well with warm colors."},
{label:"Navy Blue", color:"0x000066",descript:"The conservative favorite."},
{label:"Forest Green", color:"0x006600",descript:"Great outdoorsy look."},
{label:"Grey", color:"0x666666", descript:"An old reliable."}]
public function openEvt(event:DropdownEvent):void {
descriptBox.text="";
}
public function changeEvt(event:ColorPickerEvent):void {
descriptBox.text=event.currentTarget.selectedItem.label + ": " + event.currentTarget.selectedItem.descript;
}
</fx:Script>
<fx:Style>
.myStyle { swatchWidth:25; swatchHeight:25; textFieldWidth:95; }
</fx:Style>
<!-- Convert the Array to an ArrayCollection. Do this if
you might change the colors in the panel dynamically. -->
<fx:Declarations>
<mx:ArrayCollection id="complexDP" source="{complexDPArray}" />
</fx:Declarations>
<mx:VBox>
<mx:TextArea id="descriptBox" width="150" height="50" />
<mx:ColorPicker id="cp" height="50" width="150"
dataProvider="{complexDP}" change="changeEvt(event);"
open="openEvt(event);" editable="false" />
</mx:VBox>
</s:Application>
Related examples in the same category