PDA

View Full Version : dynamic runtime textFormat.color Unique problem


lickuid
04-11-2007, 06:27 PM
I have a unique interesting problem with setting the color value of a textFormat object at runtime. What goes on is this:
1): I have a custom color gradient color picker object that, when you mousedown and mouseover it, the rgb values change according to the pixel the mouse is over.
2): After I get the rgb values, I then convert it to a hex value in this format: 0xRRGGBB
3): that value is first assigned to a string variable, then the string variable is assigned to a number variable. this works flawlessly so far.
but here's the problem...
4):I have already created a textFormat Object, but want to assign the hex value of the number variable to the textFormat Object. example:
var hexString:String = '0x' + //formula for calculating hex
var hexNum:Number = hexString
my_fmt.color = hexNum

the last line above always returns '0' when I trace() it when I'm expecting to see that hex variable. I also tried hardcoding the hexNum variable with a hex value and this worked, but I need it to pull from that changing variable at runtime, does anyone know how to pull this off?
Much thanks to all help.
Note. I tried using the setTransform() method also to no avail. I'd rather use hex instead of the transform method, but I'll take what I can get.

lickuid
04-11-2007, 07:10 PM
Alright, I found the answer... I had to break down the hex value so that it only showed the RRGGBB values and not the 0x part... I then retyped the textformat object color code:

texformat.color = "0x" + hexval;

For some reason, this did the trick... go figure:)

lickuid
04-12-2007, 02:33 AM
Okay, here's what actually works..... The previous way seemed to work but then I went to another machine and it didn't anymore... so I tried a new method

var hexString:String = "0x" ;// + calculated hex from rgb here
var hexNum:Number = new Number(hexString);

my_fmt.color = hexNum;

Hopefully, this method will continue to work... I don't know why it seems like the old method worked once and not again.. that makes absolutely no sense and was probably not what happened

Cheers!