âš ī¸ Warning âš ī¸ Deprecated Code! This video tutorial contains outdated code.
💡 If you wish to update it, any AI assistant will update the code for you in seconds.

ColorPicker Component Tutorial

Published : November 14, 2014   •   Last Edited : November 24, 2025   •   Author : Adam Khoury
In this Flash ActionScript 3.0 tutorial we show how to dynamically program the ColorPicker component. Learn how to allow users to change colors on elements you want, and also learn how to access the value of their choice if using it in a form application.
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
var rectWidth:uint = 450;
var rectHeight:uint = 300;
var bgColor:uint = 0xFFCC00;
var borderColor:uint = 0x000000;
var borderSize:uint = 2;
var cornerRadius:uint = 12;
var colorPicker:ColorPicker = new ColorPicker();
colorPicker.editable = true;
colorPicker.move(20,10);
addChild(colorPicker);
drawRoundedRect();
function drawRoundedRect ():void {
    var roundedRect:Shape = new Shape;
    roundedRect.graphics.beginFill(bgColor);
    roundedRect.graphics.lineStyle(borderSize, borderColor);
    roundedRect.graphics.drawRoundRect(0,0, rectWidth, rectHeight, cornerRadius);
    roundedRect.graphics.endFill();
    roundedRect.x = 60;
    roundedRect.y = 60;
    addChild(roundedRect);
}
colorPicker.addEventListener(ColorPickerEvent.CHANGE, colorChangeHandler);
function colorChangeHandler(event:ColorPickerEvent):void {
    var newuint:uint = uint("0x"+event.target.hexValue);
    bgColor = newuint;
    removeChildAt(numChildren -1);
    drawRoundedRect();
}