English 中文(简体)
Flex TitleWindow模拟拖放并防止拖动几秒钟?
原标题:Flex TitleWindow simulate drop and prevent dragging for a few seconds?

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

这是一个非常不寻常的问题,但它将比每一点都更方便地找到解决方案

P.S:整个想法如下:当我用鼠标拖动一个TitleWindo实例时,如果TitleWindow碰到了它的父容器的边界,那么就可以放下TitleWindow,并且不可能进一步移动(模拟释放鼠标按钮)。如果我想再次移动它,那么我应该再次单击标题窗口标题并抓取它。

最佳回答

@约丹:

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

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>
问题回答

暂无回答




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签