`

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>
分享到:
评论

相关推荐

    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. - ...

    App Inventor appendix_B

    根据给定文件的部分内容,我们可以总结出App Inventor的一些关键知识点。App Inventor是一款由Google开发的编程平台,用户可以通过图形化界面构建Android应用程序。该文档主要介绍了App Inventor的基本组件,包括...

    窗口大小调整软件

    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 ...

    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...

    APP inventor指令集2

    从给定的内容来看,这里是一系列关于Google App Inventor的编程指南,它提供了一系列可视化的编程组件和块,使得非专业的开发人员能够创建Android应用程序。文档中提到的是第二部分的指令集,介绍了基础组件(Basic ...

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

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

    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 ...

    Sap Ruby Ajax

    When a user is dragged from one list to the other, an AJAX request is sent to the server to update the user's lock status in SAP. Here's a basic example of how this can be achieved: 1. **Server-Side...

    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 ...

    Qt drag和drop演示

    mimeData-&gt;setText("Dragged Text"); drag-&gt;setMimeData(mimeData); drag-&gt;exec(); ``` 在目标对象上,你需要覆盖`dragEnterEvent()`, `dragMoveEvent()`, 和 `dropEvent()`。在这些事件中,你可以检查MIME类型是否...

    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 ...

    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