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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值