开发者

Flex TitleWindow simulate drop and prevent dragging for a few seconds?

I wish while I am dragging and moving around TitleWindow instance and a specific event occure to simulate drop of the window, and not further moving been possible for a few seconds.

It is very unusual question but it will be more than handy each point to a solution

P.S: The whole idea is as follow: When I am dragging a TitleWindo instance with the mouse, and if the TitleWindow hit the border of it's parent container then to drop the TitleWindow, and not further moving is possible (simulating release mouse button). If I wish to mov开发者_StackOverflowe it again, then I should click the TitleWindow title again and grag it.


@Yordan:

Let's see if I understand you correctly. The demo below will "stop" a window from being drug offstage. When you try to drag it off the top or left border, it will "simulate the release mouse button" as you requested. The right and bottom border won't cause this to occur.

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜