可拖拽的BOX

如果你想不用panel或TitleWindow而自定义popup,但是这个popup并不能拖动,则对box进行了improve.
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" mouseDown="titleBar_mouseDownHandler(event)">
    <mx:Script>
        <![CDATA[
            import mx.core.UIComponent;
            
            private var regX:Number;
            private var regY:Number;
            public var documentParent : UIComponent;
            public var closeButton : UIComponent;
            
            /**
             *  Called when the user starts dragging a Panel
             *  that has been popped up by the PopUpManager.
             */
            protected function startDragging(event : MouseEvent) : void
            {
                regX = event.stageX - documentParent.x;
                regY = event.stageY - documentParent.y;
                
                systemManager.addEventListener(
                    MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);
        
                systemManager.addEventListener(
                    MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);
        
                systemManager.stage.addEventListener(
                    Event.MOUSE_LEAVE, stage_mouseLeaveHandler); 
            }
            /**
             *  Called when the user stops dragging a Panel
             *  that has been popped up by the PopUpManager.
             */
            protected function stopDragging() : void
            {
                systemManager.removeEventListener(
                    MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);
        
                systemManager.removeEventListener(
                    MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);
        
                /* systemManager.stage.removeEventListener(
                    Event.MOUSE_LEAVE, stage_mouseLeaveHandler); */
        
                regX = NaN;
                regY = NaN;
            }
            /**
             *  @private
             */
            private function titleBar_mouseDownHandler(event:MouseEvent) : void
            {
                // A mouseDown on the closeButton will bubble up to the titleBar,
                // but it shouldn't start a drag; it should simply start the
                // normal mouse/Button interaction.
                if (event.target == closeButton)
                    return;
                if (isNaN(regX) && documentParent.isPopUp)
                    startDragging(event);
            }
            /**
             *  @private
             */
            private function systemManager_mouseMoveHandler(event:MouseEvent) : void
            {
                // during a drag, only the Panel should get mouse move events
                // (e.g., prevent objects 'beneath' it from getting them -- see bug 187569)
                // we don't check the target since this is on the systemManager and the target
                // changes a lot -- but this listener only exists during a drag.
                event.stopImmediatePropagation();
                documentParent.move(event.stageX - regX, event.stageY - regY);
            }
            /**
             *  @private
             */
            private function systemManager_mouseUpHandler(event:MouseEvent) : void
            {
                if (!isNaN(regX))
                    stopDragging();
            }
            /**
             *  @private
             */
            private function stage_mouseLeaveHandler(event:Event) : void
            {
                if (!isNaN(regX))
                    stopDragging();
            }
        ]]>
    </mx:Script>
</mx:HBox>

你可能感兴趣的:(xml,UP)