http://www.freesitesource.com/2009/0305/542.html

 



    <mx:Style>    
        .myStyle {
            color: red;
        }
    
</mx:Style>   

    
<mx:Script><![CDATA[
        import mx.styles.StyleManager;

        public function initApp(e:Event):void {
            /* Type selector; applies to all Buttons and subclasses of Button. */
            StyleManager.getStyleDeclaration("Button").setStyle("fontSize",24); 

            /* Class selector; applies to controls using the style 
               named myStyle. Note that class selectors must be prefixed 
               with a period. */
            StyleManager.getStyleDeclaration(".myStyle").setStyle("color",0xCC66CC);

            /* Global style: applies to all controls. */
            StyleManager.getStyleDeclaration("global").setStyle("fontStyle","italic");
        }
        private function changebt(evt:MouseEvent):void
        {
            StyleManager.getStyleDeclaration(".myStyle").setStyle("color",0xffff00);
        }
    
]]></mx:Script>

    
<mx:Button id="myButton" click="changebt(event)" label="Click Me" styleName="myStyle"/>

    
<mx:Label id="myLabel" text="This is a label." styleName="myStyle"/>

</mx:Application>

相关文章: