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.
Use isPopUp
Set to true by the PopUpManager to indicate that component has been popped up.
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.
}
}
You can check if the object exists with an if block
if(findPopup)
findPopUp.visible=true;
assuming you turned of the visibility off to hide the window. You can of course destroy the object and recreate it if desired. In this case, you don't need that if block because it'll be reconstructed from scratch.
You can still use that if logic to be sure if somewhere in your code, something has already created your popup object. Maybe another class will be doing that behind the scenes so the basic idea is to guarantee that such object exists or not.
[Edit:]
Didn't know you were using PopUpManager. Please use Ranhiru Cooray's answer.
A reminder that PopUpManager has it's own method to put a pop up in front of all other objects: bringToFront(popup)
[/Edit]
Are you trying to find out if the pop up has been added to the stage or if it is still actually visible on the screen and not hidden behind other display objects ?
If it's the first, you could find out with a search (flex 3)
// popUpContainer is the object containing the pop up
if (popUpContainer.contains(FindPopup.getInstance()))
{
// The popup was added to stage
}
else
{
popUpContainer.addChild(FindPopup.getInstance());
}
If it's the second, you could make sure it is visible by adding it to the application root and making sure it has the highest index. But it's hard to test if it's actually being shown on the screen, since it could be 40% or 60% hidden behind other objects.
// Placing the pop up on top of other display objects in the application root
this.setChildIndex(FindPopup.getInstance(), this.numChildren - 1);
精彩评论