我收到以下错误:
1119: Access of possibly undefined property color through a reference with static
type mx.controls:Label.
问题是,在 MXML 中,颜色是标签的一个属性。但如果我试着说类似的话:
lblUpgrade.color = "#000000";
它抛出这个错误。在过去的 45 分钟里,我一直在努力寻找解决方法。如何在运行时设置它?谢谢!
我收到以下错误:
1119: Access of possibly undefined property color through a reference with static
type mx.controls:Label.
问题是,在 MXML 中,颜色是标签的一个属性。但如果我试着说类似的话:
lblUpgrade.color = "#000000";
它抛出这个错误。在过去的 45 分钟里,我一直在努力寻找解决方法。如何在运行时设置它?谢谢!
Label没有color
属性,而是有一个颜色样式,可以这样设置:
lblUpgrade.setStyle("color","#000000");
在 as3 中可以这样访问样式
lblUpgrade.setStyle("color","#000000");
color 是一种样式而不是属性,您可以使用setStyle
. 同样使用 as30x
代替#
颜色,但也许这适用于样式。
lblUpgrade.setStyle("颜色", "0x000000");
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.