15.3. Applying Styles to Component Types

Problem

You want to apply the same style settings to all instances of the same component type within your Flash movie.

Solution

Define an ActionScript style object with the component class name.

Discussion

In some cases, you may want to apply particular style settings to all instances of a particular component. For example, you may want to apply one set of style settings to all radio buttons and another set of style settings to all text inputs. You can apply the same set of style settings to the entire component type by defining an Action-Script style object with the same name as the component class. For example, if you want to apply the same style settings to all radio buttons, you can define a style object with the name RadioButton (using the proper capitalization is important.) As with the style objects you create, in order to apply them to groups (as discussed in Recipe 15.2), you should assign the style object to the _global.styles object. Therefore, if you want to define a style object to determine the style settings for all the radio buttons in your Flash movie, your code will look like the following:

	_global.styles.RadioButton = new mx.styles.CSSStyleDeclaration();

After you’ve declared the style object as shown in the preceding code, you need only assign the values to the specific styles you want to set. In order to do that, use the setStyle( ) by calling it from the style object. The following is an example in which the themeColor and ...

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.