Programatically Altering Font Face, Size, Weight & Color Of A Flex Label/Text Component

actionscript-3apache-flexrich-internet-application

I can change the color of the label in Flex Builder, I can even BIND the color to a variable and that works, but I can't find the Color PROPERTY in order to change or reference it programatically! What is the ActionScript 3.0 code to change the font or color of a piece of text in a Flex RIA – or is caring in what color your text appears too bizzarre a request for a RIA? I wrote whole applications after just minutes of "learning" flex, how come it's taken me three days and I still can't change the color of my stupid label?!

Best Answer

You're running into the difference between properties and styles (sometimes called style properties to confuse you). For a UIComponent, color is typically a style.

In mxml, both are initialized as XML attributes; in Actionscript, properties are straightforward member variables, while styles are dealt with by the StyleManager.

In short, you set styles by calling UIComponent.setStyle:

label.setStyle("color", 0xFFFFFF);
Related Topic