Solved

setRGB for a text box?

Posted on 2006-10-20
5
188 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

820 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