Flex:如何确定PopUpManager窗口是打开的(还是已关闭)?

时间:2011-09-06 17:03:09

标签: flex events flash-builder popupwindow

在Flex(Flash Builder 4)中,我通过PopUpManager.addPopUp打开一个新窗口。我有在我的组件中运行的计时器代码,我需要在窗口打开时停止我的计时器,并在窗口关闭时再次启动计时器。

我认为在打开窗口的功能中停止计时器很容易,但是如何在窗口关闭时再次启动计时器?

有没有办法判断组件前面是否有弹出窗口,或者是否仍然通过PopUpManager打开特定的弹出窗口?

也许事件是更好的方法?

谢谢!

3 个答案:

答案 0 :(得分:0)

活动!是要走的路。 发射/关闭期间的火灾事件。在事件处理程序中添加逻辑!

答案 1 :(得分:0)

您可以使用以下代码检查打开的弹出窗口是否已关闭。 如果关闭,你可以停止计时器。

  //set the flag to find your popup window is exist or not.
  private var isPopupExist:Boolean = false;

  private function closePopUpWindow():void
  {

   var systemManager:SystemManager = FlexGlobals.topLevelApplication.systemManager;
   //Returns a list of all children.
   var childList:IChildList = systemManager.rawChildren;
   for(var i:int=childList.numChildren-1;i>=0;i--)
   {
      var childObject:* = childList.getChildAt(i);
      //If child object is Uicomponent.
      if (childObject is UIComponent)
      {
      var uiComponent:UIComponent = childObject as UIComponent;
      //If uicomponent is popup and class name is equal to **your popup component name** here i am using "ChatComp".

          if (uiComponent.isPopUp && uiComponent.className == "ChatComp")
          { 
                  isPopupExist = true;
          }
      }
   } 
}

在你的计时器中,

  private function checkPopUpExistance():void
  {
     call closePopUpWindow() function for every 1 sec or any seconds(your wish) to check whether popup is exist or not.
     if(isPopupExist)
     {
       here you stop the timer.
     }
 }

现在,您可以在打开弹出窗口时启动计时器。

答案 2 :(得分:-1)

popupmanager是一个单例类,所以你可以很容易地知道用他的ChildList创建了多少个弹出窗口

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/PopUpManagerChildList.html