User Guide
86 Customizing Components
To create a component instance and set multiple properties simultaneously
using ActionScript:
1. Drag a component to the library.
2. Open the Actions panel and select Scene 1, then select Layer 1: Frame 1.
3. Enter the following syntax to create an instance of the component and set its properties:
createClassObject(className, "instance_name", depth, {style:"setting",
style:"setting"});
So, for example, with a Button component in the library, the following ActionScript
creates a button instance
my_button at depth 1 with the text styles set to purple
and italicized:
createClassObject(mx.controls.Button, "my_button", 1, {label:"Hello",
color:"0x9900CC", fontStyle:"italic"});
For more information, see UIObject.createClassObject().
4. Select Control > Test Movie to view the changes.
For a list of styles supported by a particular component, see the component’s entry in the
Components Language Reference.
Setting global styles
By default, all components adhere to a global style declaration until another style declaration
is attached to the component (as in “Setting custom styles for groups of components”
on page 87). The global style declaration is assigned to all Flash components built with
version 2 of the Macromedia Component Architecture. The _global object has a
style
property (
_global.style) that is an instance of CSSStyleDeclaration, and acts as the global
style declaration. If you change a style property’s value on the global style declaration, the
change is applied to all components in your Flash document.
CAUTION
Some styles are set on a component class’s CSSStyleDeclaration instance (for
example, the
backgroundColor style of the TextArea and TextInput components).
Because the class style declaration takes precedence over the global style declaration
when style values are determined, setting
backgroundColor on the global style
declaration would have no effect on the TextArea and TextInput components. For more
information about style precedence, see “Using global, custom, and class styles in the
same document” on page 92. For more information about editing a component class’s
CSSStyleDeclaration, see “Setting styles for a component class” on page 89.