Solved

setRGB for a text box?

Posted on 2006-10-20
5
185 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:Aspirin99
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
kamermans earned 500 total points
ID: 17777954
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 17779260
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
 
LVL 1

Author Comment

by:Aspirin99
ID: 17779797
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
 
LVL 13

Expert Comment

by:kamermans
ID: 17780952
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
 
LVL 1

Author Comment

by:Aspirin99
ID: 17781089
Very interestring. I'll give it a shot. THanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now