Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

setRGB for a text box?

Posted on 2006-10-20
5
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
kamermans earned 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

721 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