Jul 21
接下来的例子演示了包括使Alert控件文本不可选中(Flex中如何通过selectable属性创建一个文本不可选中Alert的例子中有介绍),Alert标题是用嵌入字体,消息,按钮使用阴影效果,移除按钮边角和Skin等。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- creationComplete="showAlert()"
- applicationComplete="init()">
- <!-- Used by the ApplicationControlBar control. -->
- <mx:String id="fileName" />
- <mx:String id="fileSize" />
- <!-- Used by the Alert control. -->
- <mx:String id="message">The quick brown fox jumped over the lazy dog.
- The quick brown fox jumped over the lazy dog.</mx:String>
- <mx:String id="title">The quick brown fox jumped over the lazy dog?</mx:String>
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- private var a:Alert;
- private function init():void {
- var appInfo:LoaderInfo = Application.application.loaderInfo;
- /* Just grab the filename from the SWF URL. */
- fileName = (appInfo.url).split("/").pop();
- /* Convert bytes to kilobytes. */
- fileSize = (appInfo.bytesTotal / 1024).toFixed(2);
- }
- private function showAlert():void {
- Alert.yesLabel = "Accept";
- Alert.noLabel = "Reject";
- Alert.buttonWidth = 120;
- a = Alert.show(
- message,
- title,
- Alert.NO | Alert.YES
- );
- /* Make the Alert form's text non-selectable. */
- a.mx_internal::alertForm.mx_internal::textField.selectable = false;
- }
- ]]>
- </mx:Script>
- <mx:Style>
- @font-face{
- src: url("./fonts/base02.ttf");
- fontFamily: "Base02";
- }
- Alert {
- titleStyleName: "alertTitle";
- messageStyleName: "alertMessage";
- buttonStyleName: "alertButton";
- dropShadowEnabled: true;
- shadowDistance: 5;
- shadowDirection: right;
- cornerRadius: 0;
- embedFonts: true;
- fontFamily: Base02;
- }
- .alertTitle {
- letterSpacing: 0;
- fontSize: 14;
- color: red;
- }
- .alertMessage {
- letterSpacing: 0;
- fontSize: 10;
- fontWeight: normal;
- color: black;
- }
- .alertButton {
- letterSpacing: 0;
- fontSize: 11;
- cornerRadius: 10;
- fontWeight: normal;
- textRollOverColor: white;
- color: red;
- skin: ClassReference(null);
- }
- </mx:Style>
- <!-- Display SWF name and file size. -->
- <mx:ApplicationControlBar id="applicationControlBar" dock="true">
- <mx:Label id="info" text="{fileName} ({fileSize}kb)" />
- </mx:ApplicationControlBar>
- <!-- Click to launch Alert control. -->
- <mx:Button label="Launch Alert" click="showAlert()" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer
