|
1<?xml version="1.0" encoding="utf-8"?>
2<!-- http://blog.flexexamples.com/2008/10/17/disabling-an-alert-control-in-flex/ -->
3<mx:Application name="Alert_enabled_test"
4 xmlns:mx="http://www.adobe.com/2006/mxml"
5 layout="vertical"
6 verticalAlign="middle"
7 backgroundColor="white">
8
9 <mx:Script>
10 <![CDATA[
11 import mx.events.FlexEvent;
12 import mx.utils.ObjectUtil;
13 import mx.controls.Alert;
14 import mx.managers.PopUpManager;
15
16 private const ENABLE_DELAY:uint = 3000; // 3 秒
17 private var a:Alert;
18
19 private function showAlert():void {
20 a = Alert.show("You have been logged out.", "Goodbye");
21 toggleButtons(a, false);
22 setTimeout(enableAlert, ENABLE_DELAY, a);
23 }
24
25 private function enableAlert(target:Alert):void {
26 toggleButtons(target, true);
27 }
28
29 private function toggleButtons(target:Alert, isEnabled:Boolean):void {
30 var buttonArr:Array = target.mx_internal::alertForm.mx_internal::buttons;
31 var btn:Button;
32 for each (btn in buttonArr) {
33 btn.enabled = isEnabled;
34 }
35 }
36 ]]>
37 </mx:Script>
38
39 <mx:Button id="button"
40 label="Logout"
41 click="showAlert();" />
42
43</mx:Application>
效果如下:
|