Another option in setting custom style declarations is you can assign the
instance directly to the component instance's
declaration in
_global.styles
•
Remove the ActionScript from steps 6 and 7 above.
•
Modify the ActionScript in step 9 to assign the
component instances:
a.setStyle("styleName", styleObj);
b.setStyle("styleName", styleObj);
c.setStyle("styleName", styleObj);
Setting styles for a component class
You can define a class style declaration for any class of component (Button, CheckBox, and so on)
that sets default styles for each instance of that class. You must create the style declaration before
you create the instances. Some components, such as TextArea and TextInput, have class style
declarations predefined by default because their
must be customized.
Caution: If you replace a class style sheet, make sure to add any styles that you want from the old
style sheet; otherwise, they will be overwritten.
The following code creates a class style declaration for CheckBox and sets the color for all check
box instances to blue:
if (_global.styles.CheckBox == undefined) {
_global.styles.CheckBox = new mx.styles.CSSStyleDeclaration();
}
_global.styles.CheckBox.setStyle("color", 0x0000FF);
Custom style settings have priority over inherited and global style settings.
Setting inheriting styles on a container
An inheriting style is a style that inherits its value from parent components in the document's
MovieClip hierarchy. If a text or color style is not set at an instance, custom, or class level, Flash
searches the MovieClip hierarchy for the style value. Thus, if you set styles on a container
component, the contained components inherit these style settings.
The following styles are inheriting styles:
•
fontFamily
•
fontSize
•
fontStyle
•
fontWeight
•
textAlign
•
textIndent
•
All single-value color styles (for example,
alternatingRowColors
styleName
. To use this approach, modify the above procedure as follows:
CSSStyleDeclaration
borderStyle
themeColor
is not)
Using styles to customize component color and text
CSSStyleDeclaration
property and bypass storing the
instance directly to the
and
backgroundColor
is an inheriting style, but
properties
71
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?