Flex中如何通过statusStyleName样式和status属性自定义显示Alert状态栏的例子

By Minidxer | January 28, 2009

接下来的例子演示了Flex中如何通过statusStyleName样式和status属性,自定义显示Alert状态栏。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white"
  6.         creationComplete="init();">
  7.  
  8.     <mx:Style>
  9.         @font-face {
  10.             src: local("Comic Sans MS");
  11.             fontFamily: myComicSansMS;
  12.             fontWeight: normal;
  13.         }
  14.  
  15.         Alert {
  16.             statusStyleName: myCustomStatusStyleName;
  17.         }
  18.  
  19.         .myCustomStatusStyleName {
  20.             color: red;
  21.             fontFamily: myComicSansMS;
  22.             fontSize: 10;
  23.             fontWeight: normal;
  24.         }
  25.     </mx:Style>
  26.  
  27.     <mx:Script>
  28.         <![CDATA[
  29.             import mx.controls.Alert;
  30.  
  31.             private var alert:Alert;
  32.  
  33.             private function init():void {
  34.                 var myMessage:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\nDonec tincidunt sollicitudin sem.";
  35.                 var myTitle:String = "The quick brown fox jumped over the lazy dog";
  36.                 alert = Alert.show(myMessage, myTitle);
  37.                 alert.status = "status message";
  38.             }
  39.         ]]>
  40.     </mx:Script>
  41.  
  42.     <mx:ApplicationControlBar dock="true">
  43.         <mx:Button label="Launch alert" click="init();" />
  44.     </mx:ApplicationControlBar>
  45.  
  46. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Alert | No Comments » | 1,598 views Tags: , ,

Search Posts