Mar 02

接下来的例子展示了如何利用静态的StyleManager.getStyleDeclaration()事件和 StyleManager.getStyleDeclaration() 事件,来设定Flex中Alert的风格。


下面是代码:

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/02/29/styling-alert-controls-in-flex-using-the-stylemanager-class-and-setstyle-methods/ -->
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white"
  7.         creationComplete="init();">
  8.  
  9.     <mx:Script>
  10.         <![CDATA[
  11.             import mx.controls.Alert;
  12.             import mx.styles.StyleManager;
  13.  
  14.             private var alert:Alert;
  15.             private var alertCSS:CSSStyleDeclaration;
  16.  
  17.             private function init():void {
  18.                 alertCSS = StyleManager.getStyleDeclaration("Alert");
  19.             }
  20.  
  21.             private function showAlert(color:Object):void {
  22.                 alertCSS.setStyle("modalTransparencyColor", color);
  23.                 alertCSS.setStyle("themeColor", color);
  24.                 alert = Alert.show("The quick brown fox...");
  25.             }
  26.         ]]>
  27.     </mx:Script>
  28.  
  29.     <mx:ApplicationControlBar dock="true">
  30.         <mx:Button label="Red"
  31.                 themeColor="red"
  32.                 click="showAlert('red');" />
  33.         <mx:Button label="Orange"
  34.                 themeColor="haloOrange"
  35.                 click="showAlert('haloOrange');" />
  36.         <mx:Button label="Yellow"
  37.                 themeColor="yellow"
  38.                 click="showAlert('yellow');" />
  39.         <mx:Button label="Green"
  40.                 themeColor="haloGreen"
  41.                 click="showAlert('haloGreen');" />
  42.         <mx:Button label="Blue"
  43.                 themeColor="haloBlue"
  44.                 click="showAlert('haloBlue');" />
  45.     </mx:ApplicationControlBar>
  46.  
  47. </mx:Application>
执行效果:

原文作者:Peter deHaan 翻译:minidxer

written by Minidxer  |  tags: , , ,

Related Post

Leave a Reply