views:

68

answers:

2
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.

A: 

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.

Amarghosh
This is what I want to do: I want the value of `myColorPicker.hexValue` into something like this. `graphics.Linestyle(2, myColorPicker.hexVale/someVariableName, 1)`
masb
Where do you want to do this - did you get any error when you tried this?
Amarghosh
yeah, but i solved the problem now. The code is definitely not clean and easily readable, but it is good enough for now.
masb
A: 
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);
}
masb
see my updated answer
Amarghosh