UIObject.setStyle()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX 2004.

Usage

componentInstance.setStyle(propertyName, value)

Parameters

propertyName A string indicating the name of the style property. Supported styles vary depending on the component. Each component has a different set of styles that you can set. For example, Customizing the TextArea component shows a table of styles, including fontWeight. So, for a TextArea component, you can use fontWeight as the propertyName parameter.

value The value of the property. If the value is a string, it must be enclosed in quotation marks.

Returns

Nothing.

Description

Method; sets the style property on the style declaration or object. If the style property is an inheriting style, the children of the object are notified of the new value.

For a list of the styles that each component supports, see individual component entries. For example, Button component styles are listed in Using styles with the Button component.

To enhance performance, you can change styles before they are loaded, calculated, and applied to the objects in your SWF file. If you can change styles before the styles are loaded and calculated, you do not have to call setStyle.

Adobe recommends that you set properties on each object because objects are instantiated to improve performance when you use styles. When you dynamically attach instances to the Stage, set properties in the initObj parameter for the call that you make to UIObject.createClassObject(), as shown in the following ActionScript:

createClassObject(ComponentClass, "myInstance", 0, {styleName:"myStyle", color:0x99CCFF});

NOTE

 

This example uses the myStyle custom style declaration. To change multiple properties, or change properties for multiple component instances, create a custom style declaration. Flash renders a component using a custom style declaration faster than it renders a component using UIObject.setStyle() for multiple properties. For more information, see Setting custom styles for groups of components in Using ActionScript 2.0 Components.

Example

The following code sets the fontWeight style property of the cb check box instance to bold:

cb.setStyle("fontWeight", "bold");

Flash CS3