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?
LVL 1
Aspirin99Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kamermansConnect With a Mentor Commented:
Make sure you put quotes around the color in the HTML font tag's attibutes:

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

I have used this method in many occasions without a problem.  Also make sure you use the html methods of the textfield:

myTextField.html = true;
myTextField.htmlText = _parent.topText;

You can't use setRGB() to set the color of a textfield.
0
 
Aneesh ChopraCommented:
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
0
 
Aspirin99Author Commented:
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.
0
 
kamermansCommented:
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.
0
 
Aspirin99Author Commented:
Very interestring. I'll give it a shot. THanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.