Flex TitleWindow模拟掉落并防止拖动几秒钟?

时间:2011-05-31 13:51:42

标签: flex actionscript-3 move drag

我希望当我在TitleWindow实例上拖动和移动时,会发生一个特定事件来模拟窗口的下降,并且几秒钟内无法进一步移动。

这是一个非常不寻常的问题,但每个解决方案都会非常方便

PS:整个想法如下:当我用鼠标拖动TitleWindo实例时,如果TitleWindow点击它的父容器的边框然后删除TitleWindow,则不能进一步移动(模拟释放鼠标)按钮)。如果我想再次移动它,那么我应该再次单击TitleWindow标题并抓住它。

1 个答案:

答案 0 :(得分:2)

@Yordan:

让我们看看我是否理解正确。下面的演示将“停止”一个窗口不在药物后台。当您尝试将其拖离顶部或左侧边框时,它将根据您的请求“模拟释放鼠标按钮”。右边界和下边界不会导致这种情况发生。

<强> AutoDropTitleWindow.mxml:

<?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" minWidth="955" minHeight="600" creationComplete="setup()">
<fx:Script>
    <![CDATA[
        import mx.managers.PopUpManager;

        private function setup() : void {
            var titleWin:MyTitleWindow = PopUpManager.createPopUp(this, MyTitleWindow, false) as MyTitleWindow;
            PopUpManager.centerPopUp(titleWin);
        }
    ]]>
</fx:Script>

</s:Application>

<强> MyTitleWindow.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
           creationComplete="setup()"
           >

<fx:Script>
    <![CDATA[
        import spark.events.TitleWindowBoundsEvent;

        private function setup(): void {
            addEventListener(TitleWindowBoundsEvent.WINDOW_MOVING, dragWatcher);
        }

        protected function dragWatcher(event:TitleWindowBoundsEvent):void
        {
            if (event.afterBounds.left < 0) {
                event.afterBounds.left = 0;
                dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
            } else if (event.afterBounds.right > systemManager.stage.stageWidth) {
                event.afterBounds.left = systemManager.stage.stageWidth - event.afterBounds.width;
            }
            if (event.afterBounds.top < 0) {
                event.afterBounds.top = 0;
                dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
            } else if (event.afterBounds.bottom > systemManager.stage.stageHeight) {
                event.afterBounds.top = systemManager.stage.stageHeight - event.afterBounds.height;
            }
        }

    ]]>
</fx:Script>

<s:Label x="10" y="10" text="X:"/>
<s:Label x="10" y="30" text="Y:"/>

<s:Label x="40" y="10" text="{this.x}"/>
<s:Label x="40" y="30" text="{this.y}"/>

</s:TitleWindow>