Flex中如何通过messageStyleName样式自定义Alert显示内容风格的例子

By Minidxer | January 25, 2009

接下来的例子演示了Flex中如何通过messageStyleName样式,自定义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.         @font-face {
  16.             src: local("Comic Sans MS");
  17.             fontFamily: myComicSansMS;
  18.             fontWeight: bold;
  19.         }
  20.  
  21.         Alert {
  22.             messageStyleName: myCustomMessageStyleName;
  23.         }
  24.  
  25.         .myCustomMessageStyleName {
  26.             color: haloOrange;
  27.             fontFamily: myComicSansMS;
  28.             fontSize: 10;
  29.             fontWeight: normal;
  30.         }
  31.     </mx:Style>
  32.  
  33.     <mx:Script>
  34.         <![CDATA[
  35.             import mx.controls.Alert;
  36.  
  37.             private var alert:Alert;
  38.  
  39.             private function init():void {
  40.                 var myMessage:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\nDonec tincidunt sollicitudin sem.";
  41.                 var myTitle:String = "The quick brown fox jumped over the lazy dog";
  42.                 alert = Alert.show(myMessage, myTitle);
  43.             }
  44.         ]]>
  45.     </mx:Script>
  46.  
  47.     <mx:ApplicationControlBar dock="true">
  48.         <mx:Button label="Launch alert" click="init();" />
  49.     </mx:ApplicationControlBar>
  50.  
  51. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

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

Search Posts