15.6. Working with Font and Text Styles

Problem

You want to apply styles to components that affect the text and font.

Solution

Use predefined styles in Flash to change aspects of the text.

Description

Flash uses text in many different ways throughout the components. For example, text appears on buttons, as labels next to check boxes and radio buttons, and it is used to populate combo boxes and lists. But regardless of how Flash uses the text within a specific component, you can use the same group of styles. The styles are as follows:

color

The color of the text.

embedFonts

Whether or not (true or false) to embed the font in the .swf so that the text will render consistently on computers.

disabledColor

The color of disabled text.

fontFamily

The name of the font face. You can also specify one of the font groups: _sans, _serif, or _typewriter.

fontSize

The point size of the font.

fontStyle

Either normal or italic.

fontWeight

Either normal or bold.

marginLeft

The number of pixels for the right margin.

marginRight

The number of pixels for the left margin.

textAlign

Specifies how the text should align—left, center, or right.

textDecoration

Either normal or underline.

For example, if you want to globally make the text in the components red using the _typewriter font group, you can use the following code:

	_global.style.setStyle("color", "red");
	_global.style.setStyle("fontFamily", "_typewriter");

If you want to use an embedded font, make sure you’ve done the following:

  1. Set the embedFonts style ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.