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

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

问题描述



问题:
如何约束一个简单的方法来解决这个问题? Flex3中的TitleWindow被拖出屏幕/舞台?有没有办法将TitleWindow限制在查看区域?



例如:假设我有一个占用屏幕100%的应用程序。接下来,我通过PopUpManager创建一个TitleWindow。然后,我可以继续单击并按住(拖动)该窗口,然后释放鼠标按钮。那个窗口现在已经在某个地方失去了屏幕。有没有办法阻止窗口被拖出查看区域?



感谢您的帮助。

解决方案

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

 private function doMove(event:Event):void 
{//将TW保存在布局中
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;
}
}


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.

解决方案

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天全站免登陆