Link to home
Start Free TrialLog in
Avatar of Aspirin99
Aspirin99

asked on

setRGB for a text box?

I want to specify the color of a text box via XML. My variable that equals the color is:

_root.titleColor0 (which is defined as 0xFF0000 in the XML)

I want to affect the text box this way:

_parent.topText = "<P ALIGN=\"CENTER\"><FONT FACE='Verdana' SIZE='14' COLOR= _root.titleColor0 >" + "My text string here";

That doesn't work. I can trace _root.titleColor0 just fine to equal "0xFF0000", so, I think I'm having a problem with data typing. I've tried forcing it to be a String and a number, but no luck.

I've also tried using the instance name of the text box and setRGB like

var my_color:Color = new Color(_parent.topTextMc);
my_color.setRGB(_root.titleColor0);

No luck with that either. If I change either of the above to 0xFF0000, it works fine. What's the solution please?
ASKER CERTIFIED SOLUTION
Avatar of kamermans
kamermans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aneesh Chopra
Hi,

you need to pass color values in XML with "#" not with "0x"

if your variable will  have value as below:
---------
_root.titleColor0 = "#00cc00";
------------

then following code will work fine..
------------
topText = "<P ALIGN=\"CENTER\"><FONT FACE='Verdana' SIZE='14' COLOR='"+_root.titleColor0+"'  >"+"My text string here";
-----------

(I assume 'topText' is variable name of a textField which has html enabled)

Regards
Aneesh
Avatar of Aspirin99
Aspirin99

ASKER

Thanks, kamermans. That did the trick. However, I think you are mistaken about being able to use setRGB to set the color, at least it works in Flash 8 using:

var my_color:Color = new Color(_parent.topTextMc);
my_color.setRGB(0xFF0000);

You have to specify the instance name versus the variable name. It's just that I can't figure out how to get that to work with a variable replacing 0xFF0000, and I think the reason I can't is I get get the data type correct. You'd think it was a string, but that doesn't work. Hopefully, I won't have this problem when I need to change movie colors, which is my next project this morning.

aneeshchopra - Thanks, you are correct that I need to use #FF0000. However, I was using that. I just forgot to change it in the example I gave here as the last thing I tried was the setRGB, which using the 0xFF000 format to show that it is a hex number. The solution was to use the format kamermans provided, but thanks for your response. You have been very helpful in the past.
I see what you're saying :D  You can probably typecast your string like this:

var colString:String = "0xFF0000";
var colNum:Number = parseInt(colString,16);  

That would parse the string as an integer.  The "16" is the "radix" or "base" of the number - in this case we want to use 16 for hexidecimal.
Very interestring. I'll give it a shot. THanks.