masb
masb

Reputation: 2843

ColorPicker in AS3

import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;

var myColorPicker:ColorPicker = new ColorPicker();
myColorPicker.addEventListener(ColorPickerEvent.CHANGE, changeHandler);
myColorPicker.move(10, 10);
addChild(myColorPicker);

function changeHandler(event:ColorPickerEvent) {
    trace("color changed:", event.color, "(#" + event.target.hexValue + ")");
 trace(myColorPicker.hexValue);
}

I need the value of event.target.hexValue outside of the function. I'm using actions in Flash CS5.

Upvotes: 1

Views: 5103

Answers (2)

Amarghosh
Amarghosh

Reputation: 59451

Update: If you're looking for the value of selected color as uint, you can directly use the selectedColor property of ColorPicker event.target.selectedColor or color property of the ColorPickerEvent event.color


Unless you have multiple color pickers that use same change handler, the value of event.target, (or event.currentTarget to be precise), is the same as myColorPicker that can be accessed from outside the function without any problem. Hence, you can use myColorPicker.hexValue outside the function. If the code you want to access this doesn't have access to myColorPicker, you can pass the value of myColorPicker.hexValue to that function as a parameter.

If this is not what you wanted, please clarify the question.

Upvotes: 1

masb
masb

Reputation: 2843

var borderColor:uint = 0x000000;

var myColorPicker:ColorPicker = new ColorPicker();
myColorPicker.editable = true;
myColorPicker.move(10, 10);
addChild(myColorPicker);

myColorPicker.addEventListener(ColorPickerEvent.CHANGE, changeHandler);

function changeHandler (event:ColorPickerEvent):void {
    var newuint = uint("0x"+event.target.hexValue);
    borderColor = newuint;
    graphics.lineStyle(2,borderColor,1);
}

Upvotes: 2

Related Questions