Skip to main content
Known Participant
February 5, 2014
Answered

Checkbox and radio button text colour

  • February 5, 2014
  • 2 replies
  • 734 views

Hi

This might be a really simple question but I can't find the answer anywhere?!

How can I change the colour of the labels on checkboxes and radio buttons?

I tried this:

a1.setStyleProperty("textColor",0x990000);

but I get this error:

1061: Call to a possibly undefined method setStyleProperty through a reference with static type fl.controls:RadioButtonGroup.

can anyone help?

Thank you! : )

This topic has been closed for replies.
Correct answer Ned Murphy

You should use TextFormat class to assign text formatting...

var newFormat:TextFormat = new TextFormat();
// whatever font styles you want to apply

newFormat.color = 0xFF0000;

a1.setStyle("textFormat", newFormat);

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
February 5, 2014

You should use TextFormat class to assign text formatting...

var newFormat:TextFormat = new TextFormat();
// whatever font styles you want to apply

newFormat.color = 0xFF0000;

a1.setStyle("textFormat", newFormat);

dips045Author
Known Participant
February 5, 2014

Many thanks - thats worked perfectly.

Is there a way to target all the checkboxes and radiobuttons rather than indvidually?

Thank you so much

Ned Murphy
Legend
February 5, 2014

You're welcome.

The only way I know of targeting all checkboxes is to use a loop.  You could name them in a manner that allows you to use bracket notation to target them.  For instance, if you were to name them... a1, a2, a3, etc....

for(var i:int=1; i<=numCheckboxes; i++){

     this["a"+String(i)].setStyle("textFormat", newFormat);

}

Inspiring
February 5, 2014

you wrote as2, try this one:

a1.setStyle("color",0x990000);