User Guide
Using styles to customize component color and text 69
Setting styles on a component instance
You can write ActionScript code to set and get style properties on any component instance.
The
UIObject.setStyle() and UIObject.getStyle() methods can be called directly from
any component. The following syntax specifies a property and value for a component instance:
instanceName.setStyle("propertyName", value);
For example, the following code sets the accent colors on a Button instance called myButton that
uses the Halo theme:
myButton.setStyle("themeColor", "haloBlue");
Note: If the value is a string, it must be enclosed in quotation marks.
Even though you can access the styles directly as properties (for example, myButton.color =
0xFF00FF
), it’s best to use the setStyle() and getStyle() methods so that the styles work
correctly and components are redrawn with the new style settings. For more information, see
UIObject.setStyle() on page 825.
Style properties set on a component instance through
setStyle() have the highest priority and
override all other style settings discussed in the following sections.
Note: If you want to change multiple properties, or change properties for multiple component
instances, you should create a custom style. For more information, see “Setting custom styles for
groups of components” on page 69.
To set or change a property for a single component instance that uses the Halo theme:
1.
Select the component instance on the Stage.
2.
In the Property inspector, give it the instance name myComponent.
3.
Open the Actions panel and select Scene 1, then select Layer 1: Frame 1.
4.
Enter the following code to change the instance to orange:
myComponent.setStyle("themeColor", "haloOrange");
5.
Select Control > Test Movie to view the changes.
For a list of styles supported by a particular component, see the component’s entry in
Chapter 6, “Components Dictionary,” on page 91.
Setting custom styles for groups of components
You can create custom style declarations to specify a unique set of properties for groups of
components in your Flash document. You create a new instance of the CSSStyleDeclaration
object, create a custom style name and place it on the
_global.styles list
(
_global.styles.newStyle), specify the properties and values for the style, and assign the style
name to component instances that should share the same look.
To make changes to a custom style format, use the following syntax:
_global.styles.CustomStyleName.setStyle(propertyName, propertyValue);
The CSSStyleDeclaration object is accessible if you have placed at least one component instance
on the Stage.










