How to prevent a component from being dragged out of the stage in Flex 3

apache-flex

I think there is a simple solution to this question, just not simple enough for me to find it.

Question:
How do you constrain a TitleWindow in Flex 3 from being dragged off the screen/stage? Is there a way to restrict the TitleWindow to the viewing area?

Example: Let's say I have an application that take 100% of the screen. Next, I create a TitleWindow via the PopUpManager. I can then proceed to click and hold (drag) that window off the screen, then release the mouse button. That window is now lost off-screen somewhere. Is there a way to keep the window from being dragged beyond the viewing area?

Thanks for the help in advance.

Best Answer

this is a very old post, but here's another way of doing it: Whether you are extending the component or not, in the TitleWindow definition add the following line: move:"doMove(event)" Import the Application library (import mx.core.Application;) and add the doMove function:

private function doMove(event:Event):void
{//keeps TW inside layout
    var appW:Number=Application.application.width;
    var appH:Number=Application.application.height;
    if(this.x+this.width>appW)
    {
        this.x=appW-this.width;
    }
    if(this.x<0)
    {
        this.x=0;
    }
    if(this.y+this.height>appH)
    {
        this.y=appH-this.height;
    }
    if(this.y<0)
    {
        this.y=0;
    }
}
Related Topic