The ColorPicker component in Flash CS3 is a new one. The ColorPicker component displays a list of one or more swatches from which the user can select a color.By default, the ColorPicker component displays a single swatch of color on a square button in your AS3 Flash. When the user clicks this button, a panel opens to display the complete list of swatches.
You can limit the ColorPicker component to a select number of colors like so:
import fl.controls.ColorPicker;
var cp:ColorPicker = new ColorPicker();
cp.colors = [ 0x001100,
0x003300,
0x005500,
0x007700,
0x009900,
0x00BB00,
0x00DD00,
0x00FF00 ];
addChild(cp);
Or you can do something similar as to what I’ve done here with you ColorPicker component using AS3:
//(make sure you have a ColorPicker component in your library
//and a symbol on the stage with an instance name of myMC )
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
var myColorPicker:ColorPicker = new ColorPicker();
myColorPicker.editable = false;
myColorPicker.addEventListener(MouseEvent.CLICK, clickHandler);
myColorPicker.addEventListener(ColorPickerEvent.CHANGE, changeHandler);
myColorPicker.move(20, 20);
addChild(myColorPicker);
function clickHandler(event:MouseEvent):void {
event.currentTarget.open();
}
var colorTransform:ColorTransform = myMC.transform.colorTransform;
function changeHandler(event:ColorPickerEvent):void {
colorTransform.color = myColorPicker.selectedColor;
myMC.transform.colorTransform = colorTransform;
trace(“color: “, event.color, “(hex: ” + event.target.hexValue + “)”);
}
Sample Files:
Posted in: Flash Helps | Comments Off