开发者

Flex 4: Title window goes out of accessible area

I have a strange issue- I use a title window to create a message to the user. The user has the ability to move the title window around the screen so that the main screen is visible.

However if the user were to move the title window way too much, it can actually go outs开发者_如何学JAVAide the browser accessible area- the user has no option but to close the browser and start again. How do we ensure that the title window movement is limited, such that the title bar is always available for control?

I might not have worded this right- pls check the attached image

Flex 4: Title window goes out of accessible area

.


I'd listen to the move event of the TitleWindow. If the window is moved out of the visible coordinates of the application, move it back.

If you're only issue is w/ allowing the users to closet the window, then you could add a "Close" button on the bottom of the window in addition to the 'x' at the top.


If you can use a custom component I'd suggest you override the TitleWindow's move() method. I'm using the following code to restrict the window movement:

public class PopUpWindow extends TitleWindow
{
    private static const MIN_VISIBLE:int = 50;

    public override function move(x:Number, y:Number):void
    {
        var maxX:Number = stage.stageWidth - MIN_VISIBLE;
        var maxY:Number = stage.stageHeight - MIN_VISIBLE;

        if (x < 0)
            x = 0;
        else if (x > maxX)
            x = maxX;

        if (y < 0)
            y = 0;
        else if (y > maxY)
            y = maxY;

        super.move(x, y);
    }
}


This function is called on move event of titlewindow:

        protected function titlewindow1_moveHandler(event:MoveEvent):void
        {
            // TODO Auto-generated method stub
            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);
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜