How to make a Popup always on top?
iiley November 6th, 2008
Some guys asked me about this question for times, i thought i should make a post here since you want to know this too.:)
Well, all the Popups in AsWing, including JPopup and all its sub classes such as JWindow JFrame, has their owner — the first param of their constructor, for example new JFrame(owner, …), the owner specified where the popups create their assets. You can set a default owner for all popups by calling AsWingManager.init(defaultOwner, …) or AsWingManager.setRoot(defaultOwner), if there’s a default owner set, you can pass null to the popup constructors, null means to use default one.
So, how to make a popup on top of others? Yes, you already know, just make its owner on top of others, for example, there’s two sprite on your stage, sprite2 is on top of sprite1, if you call AsWingManager.setRoot(sprite1) to make sprite1 as default owner, then you created a popup with sprite2 as its owner for example topFrame = new JFrame(sprite2, …), then you’ll got topFrame always on top of other popups which created with default owner.
BTW, the owner can be a JPopup instance too, if a owner is a popup, the created popup will be its sub popup, always on top of parent popup and if parent popup hide or minimized the sub popup will be non-visible.
Here’s a demo:
public class TopPopup extends Sprite{
private var sprite1:Sprite;
private var sprite2:Sprite;
public function TopPopup(){
super();
sprite1 = new Sprite();
sprite2 = new Sprite();
addChild(sprite1);
addChild(sprite2);
AsWingManager.initAsStandard(sprite1);
createFrame(null, "Normal Frame1");
createFrame(null, "Normal Frame2");
createFrame(createFrame(null, "Parent"), "Sub").setSizeWH(100, 80);
createFrame(sprite2, "Top Frame").setSizeWH(200, 140);
}
private function createFrame(owner:*, title:String):JFrame{
var frame:JFrame = new JFrame(owner, title);
frame.setDragDirectly(true);
frame.setSizeWH(140, 100);
frame.setLocationXY(Math.random()*200, Math.random()*100);
frame.show();
return frame;
}

