Alert 显示多个按钮 代码:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" fontSize="12" > <mx:Script> <![CDATA[ import mx.controls.Alert; private var alert:Alert; private function showAlert():void { var text:String = "这里我们让他显示两个按钮"; var title:String = "This is the title of the Alert window"; alert = Alert.show(text, title, Alert.YES | Alert.NO); } ]]> </mx:Script> <mx:Button label="Alert.show()" click="showAlert();" /> </mx:Application>
检查用户按了哪个按钮把窗口关闭了代码:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" fontSize="12" > <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; private var alert:Alert; private function showAlert():void { var text:String = "还是两个窗口,但现在我已经可以知道你按的是哪一个了,哈哈"; var title:String = "This is the title of the Alert window"; alert = Alert.show(text, title, Alert.YES | Alert.NO); alert.addEventListener(CloseEvent.CLOSE, alert_close); message.text = ""; } private function alert_close(evt:CloseEvent):void { switch (evt.detail) { case Alert.CANCEL: message.text = "你按的是 `" + Alert.cancelLabel + "`."; break; case Alert.NO: message.text = "你按的是 `" + Alert.noLabel + "`."; break; case Alert.OK: message.text = "你按的是 `" + Alert.okLabel + "`."; break; case Alert.YES: message.text = "你按的是 `" + Alert.yesLabel + "`."; break; } } ]]> </mx:Script> <mx:Button label="Alert.show()" click="showAlert();" /> <mx:Label id="message" /> </mx:Application>
更简单的方法:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" fontSize="12" > <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; private var alert:Alert; private function showAlert():void { var text:String = "简单的方法,注意一下Alert.show()的第5个参数吧"; var title:String = "This is the title of the Alert window"; alert = Alert.show(text, title, Alert.YES | Alert.NO, null, alert_close); message.text = ""; } private function alert_close(evt:CloseEvent):void { switch (evt.detail) { case Alert.CANCEL: message.text = "你按的是 `" + Alert.cancelLabel + "`."; break; case Alert.NO: message.text = "你按的是 `" + Alert.noLabel + "`."; break; case Alert.OK: message.text = "你按的是 `" + Alert.okLabel + "`."; break; case Alert.YES: message.text = "你按的是 `" + Alert.yesLabel + "`."; break; } } ]]> </mx:Script> <mx:Button label="Alert.show()" click="showAlert();" /> <mx:Label id="message" /> </mx:Application>
给Alert加个Icon
// Embed 一个图片
[Bindable]
[Embed(source='assets/error.png')]
private var Icon:Class;
[Bindable]
[Embed(source='assets/error.png')]
private var Icon:Class;
Alert.show(text, title, Alert.YES | Alert.NO, null, alert_close ,Icon);
给Alert组件的标题栏也加个Icon
[Bindable]
[Embed(source='assets/titleIcon.png')]
private var TitleIcon:Class;
然后只要加一句
alert.titleIcon=TitleIcon
[Embed(source='assets/titleIcon.png')]
private var TitleIcon:Class;
然后只要加一句
alert.titleIcon=TitleIcon