Alert,TitleWindow以及PopUp的簡單分析

          這兩天為了Fluorida的closePopUp功能,讀了點Flex框架的源碼,對Alert,TitleWindow以及Flex的PopUp功能做了簡單的分析。
          【Alert和PopUp】
          Alert內部其實是調用了PopUpManager.在parent參數為null或者為Application的時候,彈出的窗口將跟當前Application在一個容器下。Alert在最頂層,Application在最底層,中間那層是一個稱之為modalWindows的控件,其實就是Alert后面那個磨砂的層。為了點到Alert上的按鈕,寫了一個小程序分析Alert的結構,不是很好讀,但是可以運行一下,看看分析出的Alert的內部結構:(大略說一下,Alert的Child有一個AlertForm,而AlertForm的Child除了第一個是TextField以外,都是按鈕)
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
              
          <mx:Script>
                  
          <![CDATA[
                      import mx.core.IChildList;
                      import mx.core.UIComponent;
                      import mx.core.IFlexDisplayObject;
                      import mx.managers.ISystemManager;
                      import mx.managers.PopUpManagerChildList;
                      import mx.managers.PopUpManager;
                      import mx.controls.Alert;
                      import mx.events.CloseEvent;
                      import mx.core.Singleton;
                      import mx.managers.IPopUpManager;
                      
                      private function showSimpleAlert():void{
                          Alert.okLabel="oKey";
                          Alert.show("Hello, World!","",15,null,alertCloseHandle);
                          var myTimer:Timer = new Timer(1000, 1);
                             myTimer.addEventListener("timer", timerHandler);
                             myTimer.start();            
                      }
                      
                      private function alertCloseHandle(event:CloseEvent):void{
                          simpleAlertShower.label = event.detail.toString();
                      }
                      
                      private function timerHandler(event:TimerEvent):void{
                          var text:String = "elements:";
                          var sm:ISystemManager = (Application.application.root as ISystemManager);
                          text+=sm.numChildren.toString();
                          text+=";\n modalWindows:";
                          text+=sm.numModalWindows.toString();
                          for(var index:int = 0; index < sm.numChildren; index++)
                          {
                              text += "\n" + index + " : ";
                              text += sm.getChildAt(index).toString(); 
                          }
                          
                          var alert:Alert = sm.getChildAt(sm.numChildren - 1) as Alert;
                          text += "\n buttonFlags : "+alert.buttonFlags;
                          text += "\n alertChildren:" + alert.numChildren;
                          for(var index:int = 0; index < alert.numChildren; index++)
                          {
                              text +="\n" + alert.getChildAt(index).toString();
                          }
                          var alertForm:UIComponent = alert.getChildAt(0) as UIComponent;
                          text += "\n alertFormChildren:" + alertForm.numChildren;
                          
                          for(var index:int = 0; index < alertForm.numChildren; index++)
                          {
                              text +="\n"+index+":"+ alertForm.getChildAt(index).toString();
                              
                          }
                          popupChildText.text = text;
                          alertForm.getChildAt(1).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
          //                var popupContainer:IChildList = (application.root as IChildList);
          //                PopUpManager.removePopUp(popupContainer.getChildAt( popupContainer.numChildren - 1 ) as IFlexDisplayObject);

                      }
                  
          ]]>
              
          </mx:Script>    
                
          <mx:Button id="simpleAlertShower" click="showSimpleAlert();" label="Click Me"/>
                
          <mx:Text id="popupChildText"/>
              
          </mx:Application>
          【關于TitleWindow】
          TitleWindow作為彈出窗口的時候,跟Alert處的位置沒什么區別,我想說的是TitleWindow的closeButton在哪里。下面這個同樣不好讀的程序可以幫助你分析TitleWindow或者說Panel里面都有用什么,以及closeButton在哪,其實就是在rawChildren的最后一個。
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
              
          <mx:Script>
                  
          <![CDATA[
                      import mx.containers.TitleWindow;
                      import mx.core.IChildList;
                      import mx.core.UIComponent;
                      import mx.core.IFlexDisplayObject;
                      import mx.managers.ISystemManager;
                      import mx.managers.PopUpManagerChildList;
                      import mx.managers.PopUpManager;
                      import mx.controls.Alert;
                      import mx.events.CloseEvent;
                      import mx.core.Singleton;
                      import mx.managers.IPopUpManager;
                      
                      private function showSimpleAlert():void{
                          var popUpWindow:TitleWindow = TitleWindow(PopUpManager.createPopUp(this,TitleWindow,true));
                          popUpWindow.width = 400;
                          popUpWindow.height = 300;
                          popUpWindow.visible = true;
                          popUpWindow.showCloseButton = true;
                          var myTimer:Timer = new Timer(2000, 1);
                             myTimer.addEventListener("timer", timerHandler);
                             myTimer.start();    
                      }
                      
                      private function alertCloseHandle(event:CloseEvent):void{
                          simpleAlertShower.label = event.detail.toString();
                      }
                      
                      private function timerHandler(event:TimerEvent):void{
                          var text:String = "elements:";
                          var sm:ISystemManager = (Application.application.root as ISystemManager);
                          text+=sm.numChildren.toString();
                          text+=";\n modalWindows:";
                          text+=sm.numModalWindows.toString();
                          text+="\n top children: ";
                          for(var index:int = 0; index < sm.numChildren; index++)
                          {
                              text += "\n" + index + " : ";
                              text += sm.getChildAt(index).toString(); 
                          }
                          
                          var titleWindow:TitleWindow = sm.getChildAt(sm.numChildren - 1) as TitleWindow;
                          text += "\n popUpWindowrawChildren:" + titleWindow.rawChildren.numChildren;
                          for(var index:int = 0; index < titleWindow.rawChildren.numChildren; index++)
                          {
                              text +="\n" + titleWindow.rawChildren.getChildAt(index).toString();
                          }
                          var titleBar:UIComponent = (titleWindow.rawChildren.getChildAt(2) as UIComponent);
                          text += " has " + titleBar.numChildren;
                          text += "\n" + titleBar.getChildAt(3).toString();
                          
                          popupChildText.text = text;
          //                var popupContainer:IChildList = (application.root as IChildList);
          //                PopUpManager.removePopUp(popupContainer.getChildAt( popupContainer.numChildren - 1 ) as IFlexDisplayObject);
                          PopUpManager.removePopUp(titleWindow);
                      }
                  
          ]]>
              
          </mx:Script>    
                
          <mx:Button id="simpleAlertShower" click="showSimpleAlert();" label="Click Me"/>
                
          <mx:Text id="popupChildText"/>
              
          </mx:Application>




          posted on 2008-03-17 00:22 咖啡屋的鼠標 閱讀(2520) 評論(0)  編輯  收藏 所屬分類: Flex

          <2008年3月>
          2425262728291
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(15)

          隨筆分類(52)

          隨筆檔案(76)

          文章分類(3)

          文章檔案(4)

          新聞檔案(1)

          收藏夾

          Flex

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 海南省| 安康市| 招远市| 微山县| 临海市| 大理市| 白银市| 固安县| 高邑县| 西贡区| 个旧市| 都江堰市| 四川省| 甘洛县| 江陵县| 桦川县| 白山市| 独山县| 古丈县| 四子王旗| 竹北市| 烟台市| 桦川县| 景泰县| 峨眉山市| 阳谷县| 湖南省| 安丘市| 天水市| 信丰县| 嘉义市| 临武县| 浦北县| 灵武市| 葵青区| 邯郸县| 车险| 民和| 砚山县| 陇南市| 得荣县|