styleManager动态改变样式
动态flex组件的样式.
使用styleManager.
http://www.freesitesource.com/2009/0305/542.html
Code
<?xml version="1.0"?>
<!-- containers\layouts\MainMyLoginForm.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<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>
<?xml version="1.0"?>
<!-- containers\layouts\MainMyLoginForm.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<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>