首页 > 设计 > WEB开发 > 正文

3.19.创建和控制Alert

2023-08-08 22:33:09
字体:
来源:转载
供稿:网友
3.19.1 问题
我们需要创建一个Alert 控件并且控制它的显示。
3.18.2 解决办法
使用mx.controls.Alert 类的show 方法并且给show 方法注册一个回调。
3.19.3 讨论
我们可以通过使用mx.controls.Alert 的静态引用,设置所有Alert 控件的属性,这些设定的属性值会一直保存到被再次覆盖为止。

Alert 类的show 方法需要一个警告所要使用的消息,一个标题,一组值以指定显示各自的Yes, No, 或者Cance 按钮,警报框的父组件,警报框关闭时的回调函数和警报框里显示的一个图标。例如:
+展开
-ActionScript
mx.controls.Alert.show("This is an alert""title of the alert", 1|2|8, this,alertClosed, iconclass);

除了前面两个参数,其余的参数都是可选参数。默认情况下,警报框会显示一个标签为OK的按钮,点击这个按钮即关闭该警报框。下面是完整的清单:
+展开
-XML
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400"
height="300">

<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.controls.Alert;
[Embed(source="../../assets/4.png")]
private var iconclass:Class
private function createAlert():void
{
mx.controls.Alert.buttonHeight = 20;
mx.controls.Alert.buttonWidth = 150;
mx.controls.Alert.yesLabel = "Click Yes?"
mx.controls.Alert.noLabel = "Click No?"
mx.controls.Alert.cancelLabel = "Click Cancel?"
mx.controls.Alert.show("This is an alert", "title of
the alert", 1|2|8, this, alertClosed, iconclass);
}
private function alertClosed(event:CloseEvent):void
{
trace(" alert closed ");
if(event.detail == Alert.YES)
{
trace(" user clicked yes ");
}e
else if(event.detail == Alert.CANCEL)
{
trace(" user clicked cancle ");
}e
else
{
trace(" user clicked no ");
}
}

]]>
</mx:Script>
<mx:Button label="Create Simple Alertclick="createAlert()"/>
</mx:Canvas>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表