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 (
trueorfalse) 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
normaloritalic.-
fontWeight Either
normalorbold.-
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, orright.-
textDecoration Either
normalorunderline.
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:
Set the
embedFontsstyle ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access