AIRClose.mxml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" showStatusBar="false"
closing="closeHandler(event)">
<mx:Script>
<![CDATA[
import org.zengrong.utils.Dialog;
private function closeHandler(evt:Event):void
{
trace(evt.toString());
evt.preventDefault();
Dialog.confirm('确定退出?', _close);
}
private function _close($yes:Boolean):void
{
if($yes) this.nativeApplication.exit();
}
]]>
</mx:Script>
</mx:WindowedApplication>

有关Dialog的用法与最新源码,详见zrong’s as3lib(下附源码)

Dialog.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package org.zengrong.utils
{
import flash.display.Sprite;
import mx.controls.Alert;
import mx.core.Application;
import mx.events.CloseEvent;
public class Dialog
{
public static function alert($info:String, $title:String=''):void
{
Alert.show($info, $title, 4, Application.application as Sprite);
}
/**
* 弹出confirm确认对话框,根据用户的交互返回是否确认布尔值
* @param $s 要显示的信息
* @param $closeFun 关闭确认对话框时调用的函数
*/
public static function confirm($s:String, $closeFun:Function):void
{
var __fun:Function = function(evt:CloseEvent):void
{
$closeFun(evt.detail == Alert.YES);
}
Alert.show($s, '', Alert.YES|Alert.NO, Application.application as Sprite, __fun);
}
}
}

留言

2009-03-01
次访问