package { import flash.events.Event;
import mx.core.FlexGlobals; import mx.events.CloseEvent; import mx.events.FlexEvent; import mx.logging.ILogger; import mx.managers.PopUpManager;
import spark.components.TitleWindow; import spark.events.TitleWindowBoundsEvent;
/** * This TitleWindow is designed so that the window cannot be dragged outside * the boundaries of the application. This component is made to be opened with <code>PopUpManager</code> * so that when it is closed, it will be removed from <code>PopUpManager</code>. * @author rrubalcava */ public class PopUpWindow extends TitleWindow { public function PopUpWindow() { super(); this.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete_handler, false, 0, true); this.addEventListener(CloseEvent.CLOSE, onCloseClicked_handler, false, 0, true); this.addEventListener(TitleWindowBoundsEvent.WINDOW_MOVE, onTitleWindowMove_handler, false, 0, true); }
/** * Right position of window when it opens. * @default */ public var popupRight:Number; /** * Left position of window when it opens. * @default */ public var popupTop:Number;
/** * X postion of window when it opens. * @default */ public var popupX:Number; /** * Y postion of window when it opens. * @default */ public var popupY:Number;
/** * Will remove all elements and this window from <code>PopUpManager</code>. * @param e */ protected function onCloseClicked_handler(e:CloseEvent):void { this.removeEventListener(CloseEvent.CLOSE, onCloseClicked_handler);
this.removeAllElements(); PopUpManager.removePopUp(this); }
/** * Will assign given position assignments when window is created. * @param e */ protected function onCreationComplete_handler(e:FlexEvent):void { this.removeEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete_handler); if (popupX > 0) this.x = popupX; else if (popupRight > 0) this.right = popupRight; if (popupY > 0) this.y = popupY; else if (popupTop > 0) this.top = popupTop; }
/** * Repositions window so that it cannot be dragged outside of <code>Application</code> area. * @param event */ protected function onTitleWindowMove_handler(event:Event):void { var w:Number = FlexGlobals.topLevelApplication["width"]; var h:Number = FlexGlobals.topLevelApplication["height"]; if (this.x < 0) this.x = 5; if (this.y < 0) this.y = 5; if (this.x > w - 25) this.x = w - this.width; if (this.y > h - 25) this.y = h - this.height; } }}
Wednesday, 14 September 2011
Popup Window with Spark (Solved Dragging Isuue)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment