Mar 02
接下来的例子展示了如何利用静态的StyleManager.getStyleDeclaration()事件和 StyleManager.getStyleDeclaration() 事件,来设定Flex中Alert的风格。
下面是代码:
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <!-- http://blog.flexexamples.com/2008/02/29/styling-alert-controls-in-flex-using-the-stylemanager-class-and-setstyle-methods/ -->
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- creationComplete="init();">
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- import mx.styles.StyleManager;
- private var alert:Alert;
- private var alertCSS:CSSStyleDeclaration;
- private function init():void {
- alertCSS = StyleManager.getStyleDeclaration("Alert");
- }
- private function showAlert(color:Object):void {
- alertCSS.setStyle("modalTransparencyColor", color);
- alertCSS.setStyle("themeColor", color);
- alert = Alert.show("The quick brown fox...");
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar dock="true">
- <mx:Button label="Red"
- themeColor="red"
- click="showAlert('red');" />
- <mx:Button label="Orange"
- themeColor="haloOrange"
- click="showAlert('haloOrange');" />
- <mx:Button label="Yellow"
- themeColor="yellow"
- click="showAlert('yellow');" />
- <mx:Button label="Green"
- themeColor="haloGreen"
- click="showAlert('haloGreen');" />
- <mx:Button label="Blue"
- themeColor="haloBlue"
- click="showAlert('haloBlue');" />
- </mx:ApplicationControlBar>
- </mx:Application>
执行效果:
原文作者:Peter deHaan 翻译:minidxer
