5

我收到以下错误:

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

问题是,在 MXML 中,颜色是标签的一个属性。但如果我试着说类似的话:

lblUpgrade.color = "#000000";

它抛出这个错误。在过去的 45 分钟里,我一直在努力寻找解决方法。如何在运行时设置它?谢谢!

4

4 回答 4

11

Label没有color属性,而是有一个颜色样式,可以这样设置:

lblUpgrade.setStyle("color","#000000");
于 2012-06-21T16:29:37.740 回答
5

在 as3 中可以这样访问样式

lblUpgrade.setStyle("color","#000000");
于 2012-06-21T16:28:59.757 回答
4

color 是一种样式而不是属性,您可以使用setStyle. 同样使用 as30x代替#颜色,但也许这适用于样式。

lblUpgrade.setStyle("颜色", "0x000000");

于 2012-06-21T16:36:50.527 回答
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.

于 2014-07-30T10:12:47.010 回答