2011-12-12 89 views
1

如果我點擊彈出窗口的父頁面,我需要關閉彈出窗口(adobe flex),非模態窗口。我必須做焦點檢查,然後在關閉彈出窗口之前做一些驗證。那麼我在想那是否有任何內置的重點檢查事件,或者我們是否需要爲此創建自定義事件?adobe flex彈出

回答

1

在彈出窗口中,您需要監聽彈出窗口本身和舞臺上的鼠標彈起事件。在彈出的對話框中,如果發現鼠標事件,請停止它進入舞臺。然後,如果您在舞臺上收到鼠標上移事件,您將知道它位於彈出窗口之外,並可以關閉彈出窗口。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" creationComplete="onCreationComplete()"> 
    <mx:Script> 
     <![CDATA[ 
      import mx.managers.PopUpManager; 

      private function onCreationComplete():void { 
       //listen for MouseUp events on the popup, and the stage 
       this.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp); 
       stage.addEventListener(MouseEvent.MOUSE_UP, handleStageMouseUp); 
      } 

      private function handleMouseUp(e:MouseEvent):void { 
       //catch any MouseUp events on the popup, 
       //and prevent them from getting to the stage 
       e.stopPropagation(); //don't let this event get to the stage 
      } 

      private function handleStageMouseUp(e:MouseEvent):void { 
       //if the stage fires a MouseUp event, the mouse event 
       //came from outside of the popup, so we can close it 
       closePopup(); 
      } 

      private function validate():Boolean { 
       //add your validate code here 
       return true; 
      } 

      private function closePopup():void { 
       if (validate()) { 
        //clean up event listeners, and close popup 
        stage.removeEventListener(MouseEvent.MOUSE_UP, handleStageMouseUp); 
        PopUpManager.removePopUp(this); 
       } 
      } 
     ]]> 
    </mx:Script> 
</mx:Canvas> 
+2

+1的意見:) – weltraumpirat

+2

所以這似乎是令人費解的方式..我想你也可以只添加爲mouseDownOutside =「handleMouseDownOutside(事件)」,以您的彈出... –