Using TextFormat to set text properties

Use the TextFormat object to format text for a component instance. The TextFormat object has properties that allow you to specify text characteristics such as bold, bullet, color, font, italic, size, and several others. You can set these properties in the TextFormat object and then call the setStyle() method to apply them to a component instance. For example, the following code sets the font, size, and bold properties of a TextFormat object and applies them to a Button instance:

/* Create a new TextFormat object to set text formatting properties. */
var tf:TextFormat = new TextFormat();
tf.font = "Arial";
tf.size = 16;
tf.bold = true;
a_button.setStyle("textFormat", tf);

The following illustration shows the effect of these settings on a button having a Submit label:

Button with new textFormat style applied to its label

Style properties set on a component instance through setStyle() have the highest priority and override all other style settings. However, the more properties you set using setStyle() on a single component instance, the slower the component will render at run time.