5

I get the following error:

1119: Access of possibly undefined property color through a reference with static
type mx.controls:Label.

The thing about that is that, in the MXML, color is an attribute of Label. But if I try to say something like:

lblUpgrade.color = "#000000";

it throws this error. I've been trying to find a work-around for the last 45 minutes. How can I set this at runtime? Thanks!

Panzercrisis
  • 4,590
  • 6
  • 46
  • 85

4 Answers4

11

Label does not have a color property, rather it has a color style which can be set like so:

lblUpgrade.setStyle("color","#000000");
NoobsArePeople2
  • 1,986
  • 14
  • 21
5

Styles are accessed like this in as3

lblUpgrade.setStyle("color","#000000");
Barış Uşaklı
  • 13,440
  • 7
  • 40
  • 66
4

color is a style not a property, you set it using setStyle. Also with as3 you use 0x instead of # for the color, but maybe that works for styles.

lblUpgrade.setStyle("color", "0x000000");

Daniel
  • 34,125
  • 17
  • 102
  • 150
2

Wow, I've been struggling for 45 minutes AFTER I found this post. I'm using Adobe CS6 (don't ask why!) and the only way that finally works for me is this:

/* Create a new TextFormat object, 
which allows you to set multiple text properties at a time. */ 

var tf:TextFormat = new TextFormat(); 
tf.color = 0xFF0000; 

/* Apply this specific text format (red text) to the Label instance. */ 
a_label.setStyle("textFormat", tf);

Hope this helps someone. Source: Adobe Help Center

You can also use TextFormat to change other properties like Font, Size etc.

Plasty Grove
  • 2,807
  • 5
  • 31
  • 42