Skip to main content
Inspiring
July 27, 2010
Question

Problem with getting and setting colorPicker selectedColor

  • July 27, 2010
  • 1 reply
  • 1760 views

Hi all, im having problem with a color picker. I set the selected color with AS, see it changed on screen but then later when I try to get the selected color value it always returns 0.

Im using Flash CS5.

To recreate the issue make a fla with a color picker on stage with the instance name line_color. Paste in the code below.


import fl.events.ColorPickerEvent;

line_color.selectedColor = 0xff0000;
trace(line_color.selectedColor); // displays 0
trace(line_color.hexValue); // displays 000000

line_color.addEventListener(ColorPickerEvent.CHANGE, changedColor );

function changedColor(e:Event)
{
    trace(line_color.selectedColor); // correctly displays the selected color value
}

Am i missing something very obvious or is this flash weirdness?

Thanks

This topic has been closed for replies.

1 reply

Chipleh
Inspiring
July 27, 2010

The value of your line_color.selectedColor needs to be a string and .hexValue needs to be an uint, something like this:

var lineColor = String("0xff0000");
line_color.selectedColor = lineColor;
trace(lineColor); // displays 00xff0000
var hxVal = uint(lineColor);
trace(hxVal); // displays 16711680

~Chipleh

Message was edited by: Chipleh - changed the code

Inspiring
July 27, 2010

Thanks for the reply but your example doesn't set selectedColor on the colorPicker then read it back from the colorPicker. It just sets some variables and traces them out.

var lineColor = String("0xff0000");
trace(lineColor); // displays 00xff0000
var hxVal = uint(lineColor);
trace(hxVal); // displays 16711680

Chipleh
Inspiring
July 27, 2010

Add a second movie clip to your stage and name it "line_color1", then replace your code with the following code:

import fl.events.ColorPickerEvent;

var lineColor = String("0xff0000");
line_color.selectedColor = lineColor;
trace(lineColor); // displays 00xff0000
var hxVal = uint(lineColor);
trace(hxVal); // displays 16711680


line_color.addEventListener(ColorPickerEvent.CHANGE, changedColor);

//changedColor();

function changedColor(e:Event)
{
    var thisLineColor = String(line_color.selectedColor);
trace(thisLineColor); // correctly displays the selected color value
changeLineColor(line_color1,thisLineColor);
}

function changeLineColor(object:MovieClip, color:Number){
//Create color transform property
     var colorchange:ColorTransform = new ColorTransform();
  //Get the color to change to from
  //the parameter being passed in
     colorchange.color = color;
  trace("color = " + color);
  //Change the color of the Movie Clip parameter
  //that is being passed
     object.transform.colorTransform = colorchange;
}


If I understand your problem correctly, this should sort it out.

~Chipleh