
Untitled
By: a guest on
Jul 1st, 2012 | syntax:
None | size: 2.87 KB | hits: 17 | expires: Never
Flex: How can I pop up a component in the center of the user's viewable area?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="3000" height="2000"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import spark.components.TitleWindow;
public var myWindow:TitleWindow = new TitleWindow;
protected function creationCompleteHandler(event:FlexEvent):void
{
myWindow.title = "My Title Window";
PopUpManager.addPopUp(myWindow, DisplayObject(FlexGlobals.topLevelApplication), false);
PopUpManager.centerPopUp(myWindow);
}
]]>
</fx:Script>
<s:BorderContainer width="3000" height="2000" backgroundColor="0x000000" />
</s:Application>
+==========================+---------------------+
| Viewable Area | |
| | |
| +-------------+ | |
| | I want the | | |
| | popup to | | |
| | go here. | | |
| +-------------+ | |
| | |
| | |
+==========================+ |
| |
| Rest of Application |
| |
| |
| |
| |
+------------------------------------------------+
+------------------------------------------------+
| |
| Rest of Application |
| |
| |
| +===========================+ |
| | Viewable Area | |
| | | |
| | +-------------+ | |
| | | I want the | | |
| | | popup to | | |
| | | go here. | | |
| | +-------------+ | |
| | | |
| | | |
| +===========================+ |
| |
+------------------------------------------------+
dlg.x = (this.stage.stageWidth / 2) - (dlg.width / 2);
dlg.y = (this.stage.stageHeight / 2) - (dlg.height / 2);