`

how to keep dragged TitleWindow within Flex app boundary

阅读更多

I am using PopupManager in FB4 to display a custom dialog.

    popwin = new TitleWindow(); 
    popwin.addElement(myCustomDialog);
    PopUpManager.addPopUp(popwin,this,false);
    PopUpManager.centerPopUp(popwin);

It's possible to drag the popped up TitleWindow and let go of it when its gray title bar lies outside the bounds of the Flex app rectangle, and then the popup cannot be grabbed again. It's also possible to drag the TitleWindow downwards so it becomes completely invisible below the bottom edge of the Flex app rectangle. When the Flex app bounds are less than the full browser window, and the user is working quickly, this chances of this happening increase. Is there a simple setting that will keep this from happening, or must the programmer intercept the behavior during the drag operation?

Thanks Tim

 

Hey, there isn't a simple setting to prevent this from happening from my knowledge. All you need to do is watch it every time it moves and make sure it stays within certain bounds. You could then abstract that event handler into some Controller class if you'd like.

Here's a basic example:

 

 

<?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"
    creationComplete="creationCompleteHandler()">

    <fx:Script>
        <![CDATA[
            import flash.geom.Rectangle;
            import mx.core.FlexGlobals;
            import mx.core.UIComponent;
            import mx.events.MoveEvent;
            import mx.managers.PopUpManager;
            import spark.components.TitleWindow;

            protected function creationCompleteHandler():void
            {
                var window:TitleWindow = new TitleWindow();
                PopUpManager.addPopUp(window, this, false);
                PopUpManager.centerPopUp(window);
                window.addEventListener(MoveEvent.MOVE, window_moveHandler);
            }

            protected function window_moveHandler(event:MoveEvent):void
            {
                var window:UIComponent = event.currentTarget as UIComponent;
                var application:UIComponent = FlexGlobals.topLevelApplication as UIComponent;
                var bounds:Rectangle = new Rectangle(0, 0, application.width, application.height);
                var windowBounds:Rectangle = window.getBounds(application);
                var x:Number;
                var y:Number;
                if (windowBounds.left <= bounds.left)
                    x = bounds.left;
                else if (windowBounds.right >= bounds.right)
                    x = bounds.right - window.width;
                else
                    x = window.x;
                if (windowBounds.top <= bounds.top)
                    y = bounds.top;
                else if (windowBounds.bottom >= bounds.bottom)
                    y = bounds.bottom - window.height;
                else
                    y = window.y;
                window.move(x, y);
            }

        ]]>
    </fx:Script>

</s:Application>
分享到:
评论

相关推荐

    This example shows how to show the windows contents while th

    This example shows how to show the windows contents while the window is being dragged.

    VB编程资源大全(英文源码 表单)

    showdrag.zip This example shows how to show the windows contents while the window is being dragged.&lt;END&gt;&lt;br&gt;24 , avb-gradient.zip This bas is composed of 35 Differant Gradient Color Fades....

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD Added checkbox "Keep connector's link" in flex-document property form. - FIX Remaks panel focusing on main form (via PostMessage), since TreeInspector in FlexEditSE captures focus on self. - ...

    窗口大小调整软件

    You can find out how to donate on the website. Changelog --------- 0.7 - 2009-04-24: Added StickyScreen which makes windows automatically stick to the screen borders without needing shift (off by ...

    Meet the Kinect: An Introduction to Programming Natural User Interfaces

    I dragged as many friends as I could down to the store so they could see this amazing technology in action. That said, this book is the unofficial manual for how to take a Kinect and use it outside ...

    Android代码-StickySnot

    If you want to make your views sticky and can be dragged like snot eh...And this library will show you a some way. It can make you view behave like this: how to use Step 1. Add the JitPack repository...

    v-dragged-用于拖动事件检测的Vue 2.x指令插件。-Vue.js开发

    v-draged Vue指令插件,用于拖动事件检测。 注意:该伪指令侦听鼠标/触摸事件,并为何时拖动事件检测...安装npm install-从'vue'保存v-dragged导入Vue从'v-dragged'导入VDragged Vue.use(VDragged)示例在您的组件中:

    Cracking-the-Coding-Interview-Dragged.pdf

    Cracking-the-Coding-Interview-Dragged.pdf

    Sortable前端框架

    scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) { data...

    EasyNSE 0.2

    Drop Handler - Add clipboard formats to a file object when it is copied to the clipboard or dragged and dropped. At first this seems like not a very useful extension but check out the demo. This one ...

    Android代码-DragScaleCircleView

    A custom imageview that provides the circle window can be dragged and scaled, crop image. How does it look? Why? Sometimes need to cut a picture into a circle. Install The library is published on ...

    java7帮助文档

    A work-stealing technique is used to keep all the worker threads busy, to take full advantage of multiple processors. See Fork/Join in The Java Tutorials. The directory &lt;Java home&gt;/sample/forkjoin/ ...

    DevExpress VCL 12.2.6(v2012vol2.6) 源码-例子-帮助-part1

    Q486537 - The skinned Scheduler does not paint selected or dragged events that are not adjacent to the timeline bar ExpressSkins Library B234764 - Alert windows - Window corners are rounded using ...

    DevExpress VCL 12.2.6(v2012vol2.6) 源码-例子-帮助-part2

    Q486537 - The skinned Scheduler does not paint selected or dragged events that are not adjacent to the timeline bar ExpressSkins Library B234764 - Alert windows - Window corners are rounded using ...

    WPF全景控件Panorama源码

    I say Style, as it may not be 100% in line with what the Win8 Metro tile interface does, or how it functions, but to be honest, it fitted my needs well enough and I figured it may be OK for others....

    Senfore_DragDrop_v4.1

    Delphi 3 or C++ Builder 3 support you will have to revert to version 3.7 of the Drag and Drop Component Suite. The library has been tested on NT4 service pack 5 and Windows 2000. Windows 95, 98, ME ...

    pull_to_refresh_notification:Flutter插件,用于使用PullToRefreshNotification和PullToRefreshContainer快速构建拉动刷新效果

    pull_to_refresh_notification 语言:| 小部件以构建拉动以刷新效果。 样品4个糖果 样品5糖果 用代码刷新 刷新指标模式 enum RefreshIndicatorMode { drag, // Pointer is down. armed, // Dragged far enough ...

    EmEditor中文版

    Each marker can be dragged and dropped to change the order of markers and to insert the marker text into the editor. Selecting the Customize Markers from the menu allows you to change the details ...

    Android代码-通过拖拽重排View位置的一个库

    Android Rearrangeable Layout An android layout to re-arrange child views via ...Add a ChildPositionListener to the root layout to receive updates whenever any child view is dragged (MainActivity.java) @

Global site tag (gtag.js) - Google Analytics