开发者

Flex: How to determine if a PopUpManager window is open (or when it has closed)?

In Flex (Flash Builder 4) I am opening a new window via PopUpManager.addPopUp. I have timer code that runs in my component and I need to stop my timer when that window opens and start the timer again when the window closes.

I figure it's easy enough to stop the timer in the function that opens the window, but how can I start the timer again when the window closes?

Is there a way to tell if there is a pop-up window in front of my component, or if a specific po开发者_开发技巧p-up window is still open via PopUpManager?

Maybe events are a better approach?

Thanks!


Events! is the way to go. Fire events during launch/close. Add your logic in the event Handlers!


You can use following code to check whether opened popup window is getting closed or not. if it is closed you can stop the timer.

  //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;
          }
      }
   } 
}

in your Timer,

  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.
     }
 }

Now you can start the Timer, when you opened the Popup window.


The popupmanager is a singleton class, so you can easily know how many popups have been created with his ChildList

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜