Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0

by Peter deHaan on December 28, 2008

in ColorPicker

The following example shows how you can detect when the selected color in a Flash ActionScript 3.0 ColorPicker component by listening for the change event (using the static ColorPickerEvent.CHANGE constant).

Full code after the jump.

// ActionScript 3.0
/* Requires:
 * - ColorPicker control in the Flash library
 */
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
 
var bg:Sprite = new Sprite();
bg.graphics.beginFill(0x000000);
bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
bg.graphics.endFill();
addChild(bg);
 
var colorPicker:ColorPicker = new ColorPicker();
colorPicker.addEventListener(ColorPickerEvent.CHANGE, colorPicker_change);
colorPicker.move(10, 10);
addChild(colorPicker);
 
function colorPicker_change(evt:ColorPickerEvent):void {
    trace(evt.color, colorPicker.textField.text);
    bg.graphics.beginFill(evt.color); // 16711680 #ff0000
    bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    bg.graphics.endFill();
}

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: