如何防止组件在 Flex 3 中被拖出舞台 [英] How to prevent a component from being dragged out of the stage in Flex 3

查看:17
本文介绍了如何防止组件在 Flex 3 中被拖出舞台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个问题有一个简单的解决方案,只是不够简单,我找不到它.

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

问题:如何限制 Flex 3 中的 TitleWindow 被拖出屏幕/舞台?有没有办法将 TitleWindow 限制在查看区域内?

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?

示例:假设我有一个应用程序占据了 100% 的屏幕.接下来,我通过 PopUpManager 创建一个 TitleWindow.然后我可以继续单击并按住(拖动)该窗口离开屏幕,然后释放鼠标按钮.该窗口现在在屏幕外某处丢失了.有没有办法防止窗口被拖到查看区域之外?

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?

提前感谢您的帮助.

推荐答案

这是一篇很老的帖子,但这里有另一种方法:无论是否扩展组件,在 TitleWindow 定义中添加以下行:move:"doMove(event)"导入应用程序库(import mx.core.Application;)并添加 doMove 函数:

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;
    }
}

这篇关于如何防止组件在 Flex 3 中被拖出舞台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆