15.4. Applying Styles Globally
Problem
You want to assign style settings to all component instances in your Flash movie.
Solution
Assign the settings to the _global.style
object using the setStyle( ) method.
Discussion
Flash automatically creates a style object that you can use to manage the styles of all component instances in your Flash movie. The name of the object is _global.style
. It’s a fairly common mistake for novices and experts alike to accidentally use the incorrect name by pluralizing _global.style
as _global.styles
. The _global.styles
(plural) object is a container object that Flash uses to hold all the other style objects you might define (see Recipe 15.2 and Recipe 15.3). However, the _global.style
(singular) object is an actual style object from which all component instances can inherit their style settings.
The _global.style
object is created automatically for you by Flash, so there is no need to declare it anew as with many of the other style objects you need to create (see Recipe 15.2 and Recipe 15.3). Instead, all you need to do is use the setStyle( ) method to assign new style settings. For example, the following code will set the themeColor
and fontFamily
styles for all component instances in your Flash movie:
_global.style.setStyle("fontFamily", "_typewriter"); _global.style.setStyle("themeColor", "haloOrange");
The global style settings will take effect for all component instances for which you have not otherwise applied settings for the same styles. The _global.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.