fl.managers

# StyleManager - AS3 Flash

Package | fl.managers
Class | public class StyleManager
Inheritance | StyleManager Object

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

The StyleManager class provides static methods that can be used to get and set styles for a component instance, an entire component type, or all user interface components in a Flash document. Styles are defined as values that affect the display of a component, including padding, text formats, and skins.

View the examples

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | StyleManager() Creates a new StyleManager object. | StyleManager
|  | clearComponentStyle(component:Object, name:String):void [static] Removes a style from the specified component. | StyleManager
|  | clearStyle(name:String):void [static] Removes a global style from all user interface components in a document. | StyleManager
|  | getComponentStyle(component:Object, name:String):Object [static] Gets a style that exists on a specific component. | StyleManager
|  | getStyle(name:String):Object [static] Gets a global style by name. | StyleManager
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | registerInstance(instance:UIComponent):void [static] Registers a component instance with the style manager. | StyleManager
|  | setComponentStyle(component:Object, name:String, style:Object):void [static] Sets a style on all instances of a component type, for example, on all instances of a Button component, or on all instances of a ComboBox component. | StyleManager
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | setStyle(name:String, style:Object):void [static] Sets a global style for all user interface components in a document. | StyleManager
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Constructor Detail

### StyleManager

()
Constructor

`public function StyleManager()`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Creates a new StyleManager object.

Method Detail

### clearComponentStyle

()
method

`public static function clearComponentStyle(component:Object, name:String):void`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Removes a style from the specified component.

Parameters

| `component:Object` — The name of the component from which the style is to be removed.
| `name:String` — The name of the style to be removed.

Related API Elements

clearStyle()
getComponentStyle()
setComponentStyle()

### clearStyle

()
method

`public static function clearStyle(name:String):void`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Removes a global style from all user interface components in a document.

Parameters

| `name:String` — The name of the global style to be removed.

Related API Elements

clearComponentStyle()
getStyle()
setStyle()

### getComponentStyle

()
method

`public static function getComponentStyle(component:Object, name:String):Object`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Gets a style that exists on a specific component.

Parameters

| `component:Object` — The name of the component instance on which to find the requested style.
| `name:String` — The name of the style to be retrieved.

Returns

| `Object` — The requested style from the specified component. This function returns `null` if the specified style is not found.

Related API Elements

clearComponentStyle()
getStyle()
setComponentStyle()

### getStyle

()
method

`public static function getStyle(name:String):Object`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Gets a global style by name.

Parameters

| `name:String` — The name of the style to be retrieved.

Returns

| `Object` — The value of the global style that was retrieved.

Related API Elements

clearStyle()
getComponentStyle()
setStyle()

### registerInstance

()
method

`public static function registerInstance(instance:UIComponent):void`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Registers a component instance with the style manager. After a component instance is instantiated, it can register with the style manager to be notified of changes in style. Component instances can register to receive notice of style changes that are component-based or global in nature.

Parameters

| `instance:UIComponent` — The component instance to be registered for style management.

### setComponentStyle

()
method

`public static function setComponentStyle(component:Object, name:String, style:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Sets a style on all instances of a component type, for example, on all instances of a Button component, or on all instances of a ComboBox component.

Parameters

| `component:Object` — The type of component, for example, Button or ComboBox. This parameter also accepts a component instance or class that can be used to identify all instances of a component type.
| `name:String` — The name of the style to be set.
| `style:Object` — The style object that describes the style that is to be set.

Related API Elements

clearComponentStyle()
getComponentStyle()
setStyle()

### setStyle

()
method

`public static function setStyle(name:String, style:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Sets a global style for all user interface components in a document.

Parameters

| `name:String` — A String value that names the style to be set.
| `style:Object` — The style object to be set. The value of this property depends on the style that the user sets. For example, if the style is set to "textFormat", the style property should be set to a TextFormat object. A mismatch between the style name and the value of the style property may cause the component to behave incorrectly.

Related API Elements

clearStyle()
getStyle()
setComponentStyle()
Examples How to use this example
StyleManagerExample.as
This example demonstrates how to dynamically create a DataGrid and listen to its events.

To run the example, follow these steps:

1. Add the DataGrid, Button, Label, and TextArea components to the library.
2. Save this code as StyleManagerExample.as in the same directory as your FLA file.
3. Set the Document class in the FLA file to StyleManagerExample.

Copy

    package
    {
        import fl.controls.Button;
        import fl.controls.DataGrid;
        import fl.controls.Label;
        import fl.controls.TextArea;
        import fl.core.UIComponent;
        import fl.managers.FocusManager;
        import fl.managers.StyleManager;
        import flash.display.InteractiveObject;
        import flash.display.Sprite;
        import flash.events.MouseEvent;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.text.TextFormat;

        public class StyleManagerExample extends Sprite
        {
            private var btn:Button;
            private var ta1:TextArea;
            private var ta2:TextArea;
            private var ta3:TextArea;
            private var ta4:TextArea;
            private var description:Label;
            private var dg:DataGrid;
            private var formatForInstance:TextFormat;
            private var formatForGlobal:TextFormat;

            private var testStringHTML:String = "<body><span class='heading'>Hello </span>World...</body>";
            private var testString:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce vitae turpis id nibh suscipit tincidunt. Quisque nulla dui, elementum eget, rutrum in, ultricies nec, erat. Donec ante turpis, lacinia eget, semper ac, consequat eget, neque. Maecenas eleifend pharetra quam. Quisque suscipit nibh a ipsum. Donec sit amet mi eu ligula volutpat imperdiet. Ut quis velit quis lectus laoreet eleifend. Aliquam pulvinar lorem. Cras ultrices felis sit amet urna. Cras viverra porttitor est. Nulla justo. Sed scelerisque."

            public function StyleManagerExample() {
                setupComponents();
                setupUI();
                setupStyles();
            }
            private function setupUI():void {
                var setInstanceStyleBtn:Button = new Button();
                var clearInstanceStyleBtn:Button = new Button();
                var setClassStyleBtn:Button = new Button();
                var clearClassStyleBtn:Button = new Button();
                var setGlobalStyleBtn:Button = new Button();
                var clearGlobalStyleBtn:Button = new Button();

                setInstanceStyleBtn.label = "Set Instance Style";
                clearInstanceStyleBtn.label = "Clear Instance Style";
                setClassStyleBtn.label = "Set Class Style";
                clearClassStyleBtn.label = "Clear Class Style";
                setGlobalStyleBtn.label = "Set Global Style";
                clearGlobalStyleBtn.label = "Clear Global Style";
                setInstanceStyleBtn.focusEnabled = false;
                clearInstanceStyleBtn.focusEnabled = false;
                setClassStyleBtn.focusEnabled = false;
                clearClassStyleBtn.focusEnabled = false;
                setGlobalStyleBtn.focusEnabled = false;
                clearGlobalStyleBtn.focusEnabled = false;

                setInstanceStyleBtn.move(10,310);
                clearInstanceStyleBtn.move(10,340);
                setClassStyleBtn.move(140,310);
                clearClassStyleBtn.move(140,340);
                setGlobalStyleBtn.move(270,310);
                clearGlobalStyleBtn.move(270,340);
                setInstanceStyleBtn.setSize(120,24);
                clearInstanceStyleBtn.setSize(120,24);
                setClassStyleBtn.setSize(120,24);
                clearClassStyleBtn.setSize(120,24);
                setGlobalStyleBtn.setSize(120,24);
                clearGlobalStyleBtn.setSize(120,24);

                setInstanceStyleBtn.addEventListener(MouseEvent.CLICK,setInstanceStyle);
                clearInstanceStyleBtn.addEventListener(MouseEvent.CLICK,clearInstanceStyle);
                setClassStyleBtn.addEventListener(MouseEvent.CLICK,setClassStyle);
                clearClassStyleBtn.addEventListener(MouseEvent.CLICK,clearClassStyle);
                setGlobalStyleBtn.addEventListener(MouseEvent.CLICK,setGlobalStyle);
                clearGlobalStyleBtn.addEventListener(MouseEvent.CLICK,clearGlobalStyle);

                description = new Label();
                description.move(10, 370);
                description.autoSize = TextFieldAutoSize.LEFT;
                description.text = "";

                addChild(setInstanceStyleBtn);
                addChild(clearInstanceStyleBtn);
                addChild(setClassStyleBtn);
                addChild(clearClassStyleBtn);
                addChild(setGlobalStyleBtn);
                addChild(clearGlobalStyleBtn);
                addChild(description);
            }
            private function setupComponents():void {
                dg = new DataGrid();
                dg.addItem( { Name:"John Alpha",     Number:"555-123-0101" } );
                dg.addItem( { Name:"Mary Bravo",     Number:"555-372-3322" } );
                dg.addItem( { Name:"Trevor Gamma", Number:"555-485-1212" } );
                dg.addItem( { Name:"Susan Delta",     Number:"555-987-3434" } );
                dg.move(10,10);
                dg.setSize(200,290);
                dg.columns = ["Name","Number"];
                addChild(dg);

                ta1 = new TextArea();
                ta1.move(220,10);
                ta1.setSize(150,140);
                ta1.text = testString;
                ta1.tabEnabled = true;
                addChild(ta1);

                ta2 = new TextArea();
                ta2.move(380,10);
                ta2.setSize(150,140);
                ta2.text = testString;
                ta2.tabEnabled = true;
                addChild(ta2);

                ta3 = new TextArea();
                ta3.move(220,160);
                ta3.setSize(150,140);
                ta3.text = testString;
                ta3.tabEnabled = true;
                addChild(ta3);

                ta4 = new TextArea();
                ta4.move(380,160);
                ta4.setSize(150,140);
                ta4.text = testString;
                ta4.tabEnabled = true;
                addChild(ta4);
            }
            private function setupStyles():void {
                formatForGlobal = new TextFormat();
                formatForGlobal.font = "Georgia";
                formatForGlobal.size = 10;
                formatForInstance = new TextFormat();
                formatForInstance.underline = true;
            }
            private function setInstanceStyle(e:MouseEvent):void {
                var fm:FocusManager = new FocusManager(this);
                var uiComponent:UIComponent = fm.getFocus() as UIComponent;
                if(uiComponent is TextArea) {
                    uiComponent.setStyle("textFormat",formatForInstance);
                    description.text = "The TextArea object with focus is now underlined.";
                }
            }
            private function clearInstanceStyle(e:MouseEvent):void {
                var fm:FocusManager = new FocusManager(this);
                var uiComponent:UIComponent = fm.getFocus() as UIComponent;
                if(uiComponent is TextArea) {
                    uiComponent.clearStyle("textFormat");
                    description.text = "The TextArea object with focus is no longer underlined.";
                }
            }
            private function setClassStyle(e:MouseEvent):void {
                var c:Class = TextArea;
                var styleName:String = "textPadding";
                var value:Number = 10;
                StyleManager.setComponentStyle(c,styleName,value);
                description.text = "Padding for all TextArea instances is now 10.";
            }
            private function clearClassStyle(e:MouseEvent):void {
                var styleName:String = "textPadding";
                var c:Class = TextArea;
                StyleManager.clearComponentStyle(c,styleName);
                description.text = "TextArea padding has been reset to the default.";
            }
            private function setGlobalStyle(e:MouseEvent):void {
                var styleName:String = "textFormat";
                var value:Object = formatForGlobal;
                StyleManager.setStyle(styleName,value);
                description.text = "All components now use font Georgia size 10.";
            }
            private function clearGlobalStyle(e:MouseEvent):void {
                var styleName:String = "textFormat";
                StyleManager.clearStyle(styleName);
                description.text = "Font style for all components has been cleared.";
            }
        }
    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00