Setting styles on a component instance
You can write ActionScript code to set and get style properties on any component instance.
The
UIObject.setStyle()
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
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,
), it's best to use the
0xFF00FF
correctly and components are redrawn with the new style settings. For more information, see
UIObject.setStyle()
Style properties set on a component instance through
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
groups of components" on page
To set or change a property for a single component instance that uses the Halo theme:
Select the component instance on the Stage.
1.
In the Property inspector, give it the instance name myComponent.
2.
Open the Actions panel and select Scene 1, then select Layer 1: Frame 1.
3.
Enter the following code to change the instance to orange:
4.
myComponent.setStyle("themeColor", "haloOrange");
Select Control > Test Movie to view the changes.
5.
For a list of styles supported by a particular component, see the component's entry in
Chapter 6, "Components Dictionary," on page
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.newStyle
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.
and
UIObject.getStyle()
and
setStyle()
on page
825.
69.
), specify the properties and values for the style, and assign the style
Using styles to customize component color and text
methods can be called directly from
methods so that the styles work
getStyle()
have the highest priority and
setStyle()
"Setting custom styles for
91.
_global.styles
that
myButton
myButton.color =
list
69
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?