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. For example, the following code sets the text color on a Button instance called myButton:

myButton.setStyle("color", 0xFF00FF");

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. For more information, see Setting style property values.

Note: You should not call the UIObject.setStyle() method multiple times to set more than one property. If you want to change multiple properties, or change properties for multiple component instances, you should create a custom style format. For more information, see Setting styles for specific components.

To set or change a property for a single component instance:

  1. Select the component instance on the Stage.
  2. In the Property inspector, give it the instance name myComp.
  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 blue:
    myComp.setStyle("themeColor", "haloBlue");
    

    The following syntax specifies a property and value for a component instance:

    instanceName.setStyle("property", value); 
    
  5. Select Control > Test Movie to view the changes.

    For a list of supported styles, see Supported styles.