Alert控件的用法

来源:互联网 发布:荷兰豆 中国豆 知乎 编辑:程序博客网 时间:2024/06/05 09:21
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Alert control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    
<mx:Script>
        
<![CDATA[
            import mx.controls.Alert;
            import mx.events.CloseEvent;
             
            private function clickHandler(event:Event):void {
                Alert.show("你想保存你的改变吗?", "保存改变", 3, this, alertClickHandler);
                //show(text,title,flags,parent,closeHandle,iconClass,defaultButtonFlag)
                //前两个参数分别指出弹出窗口的文字和标题,第三个参数代表了窗口中出现的按钮,第四个数this,表明alert弹出后居中的参照对象。
                //第五个参数closeHandle是函数类型,这个函数用来捕捉用户的选择,第六个参数指出对话框中出现的图标,
                //第七个参数代表对话框中默认处于被选状态的按钮,当按下回车键,该按钮的点击事件被触发
            }
        
            private function alertClickHandler(event:CloseEvent):void {
                if (event.detail==Alert.YES)
                    status.text="You answered Yes";
                else
                    status.text="You answered No";
            }

            private function secondClickHandler(event:Event):void {
                Alert.buttonWidth = 100;
                Alert.yesLabel = "Magenta";
                Alert.noLabel = "Blue";
                Alert.cancelLabel = "Green";

                Alert.show("Select a color:","Color Selection",1|2|8,this);
            }
        
]]>
    
</mx:Script>

    
<mx:Panel title="Alert Control Example" width="75%" horizontalAlign="center" paddingTop="10">
      
<mx:Text width="100%" color="blue" textAlign="center"
          text
="点这个按钮显示一个简单的window窗口."/>
      
<mx:Button label="Click Me" click="Alert.show('Hello World!', 'Message');"/>

      
<mx:Text width="100%" color="blue" textAlign="center"
          text
="点这个按钮显示一个可以供用户选择."/>
      
<mx:Button label="Click Me" click="clickHandler(event);"/>
      
<mx:Label id="status" fontWeight="bold"/>

      
<mx:Text width="100%" color="blue" textAlign="center"
          text
="Click the button below to display an Alert window that uses custom Button labels."/>
      
<mx:Button label="Click Me" click="secondClickHandler(event);"/>
    
</mx:Panel>

</mx:Application>
 
原创粉丝点击