Search code examples
actionscript-3apache-flexactionscriptflex3

How to know if a popup is already showing up on the screen in flex


I need to know if a popup (which is a singleton titlewindow, hence would be initialized only once) is already shown in the screen or not, if not then i will call a function to show it up, otherwise do something else.

I tried findPopup.focusEnabled //findPopup is the titlewindow class for popup

But it is always true irrespective of whether the popup is shown in the screen currently or not.

Thanks.


Solution

  • All objects rendered on the screen have a root:DisplayObject property. If it is removed from the screen, then root will be null. If your concern is whether the pop-up is in front of everything else, then use popUpObj.parent.setChildIndex(popUpObj, popUpObj.parent.numChildren - 1) to ensure it (more on this below). You will need to iterate through all of the parent until you reach the root itself. (With the PopUpManager, I believe that the MovieClip is added directly to the root, so it should only be once, but I don't recall at the moment)

    Everything else is obvious:

    • is alpha = 1?
    • visible = true?
    • is width > 5
    • is height > 5
    • ... I could continue, but I think the idea is pretty clear.

    On testing visibility of obscured objects:

    Honestly, this is easiest to do on the root.

    var firstParent:DisplayObjectContainer = /* 
                                                find the ancestor which is on 
                                                the root. You may need to look up 
                                                "path to root AS3"
                                             */
    var num:int = root.numChildren;
    //iterate backwards to exclude things below the target clip.
    for( var i:int = num - 1; i >= 0; i-- )
    {
         var kid:DisplayObject = root.getChildAt( i );
         if( kid == firstParent ) break; // no sense in continuing.
         if( firstParent.hitTestObject( kid ) )
         {
             // kid at least partially obscures the pop-up. Do something with it.
         }
    }