Recipe 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 object has the lowest precedence of all other style objects. Therefore, if you have applied a themeColor setting to a component instance via a component class style object, a group style object, or on the instance itself, the global themeColor style setting will not be inherited by that instance.




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net