ToggleButton创建PopUpManager弹出窗体

来源:互联网 发布:如何破解水经注软件 编辑:程序博客网 时间:2024/05/17 03:48

目的利用ToggleButton的状态(选择与未选择)打开与关闭PopUpManager弹出窗体。

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ... ><fx:Script>   <![CDATA[      import flash.utils.clearTimeout;         import flash.utils.setTimeout;                  import mx.core.FlexGlobals;         import mx.managers.PopUpManager;                  import spark.components.Button;         import spark.components.TitleWindow;                  private var timeOutMark:uint;  //定义setTimeOut唯一标识符变量          private var myTitleWin:TitleWindow;                  protected function openAlert():void         {                          myTitleWin=new TitleWindow();            myTitleWin.title="xBox One";            myTitleWin.minWidth=200;            myTitleWin.minHeight=300;                        var label:Label=new Label();            label.text="I wanna to play xBoxOne";                        myTitleWin.addElement(label);                        PopUpManager.addPopUp(myTitleWin,FlexGlobals.topLevelApplication as DisplayObject);            PopUpManager.centerPopUp(myTitleWin);                        timeOutMark=setTimeout(closeAlert,5000); //设置自动关闭的函数与时间点                     }         private function closeAlert():void{            PopUpManager.removePopUp(myTitleWin);            btnAlert.selected=false;            clearTimeout(timeOutMark);         }                  protected function openAlert_changeHandler(event:Event):void         {            // TODO Auto-generated method stub            if(btnAlert.selected==true){               openAlert();            }            else{               closeAlert();            }         }            ]]></fx:Script>   <s:ToggleButton id="btnAlert" label="Open Alert" change="openAlert_changeHandler(event)"/></s:Application>


暂不知道怎么在AS代码中为myTitleWin创建closeButton事件,有待日后补充。

setTimeOut与clearTimeOut方法与本标题无关,只为了记录
setTimeout ():uint  函数 在指定的延迟(以毫秒为单位)后运行指定的函数。
clearTimeout () 函数 取消指定的 setTimeout() 调用。
可设置超时进程的唯一数字标识符,并通过调用 clearTimeout() 方法取消进程。(本例中变量timeOutMark)
 

0 0
原创粉丝点击