Resizable TitleWindow in Flex 4

Resizable TitleWindow in Flex 4


package
{
    
    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    import mx.core.UIComponent;
    import mx.events.SandboxMouseEvent;
    
    import spark.components.TitleWindow;
    
    /**
     *  ResizableTitleWindow is a TitleWindow with
     *  a resize handle.
     */
    public class ResizableTitleWindow extends TitleWindow
    {
        
        //--------------------------------------------------------------------------
        //
        //  Constructor
        //
        //--------------------------------------------------------------------------
        
        /**
         *  Constructor.
         */
        public function ResizableTitleWindow()
        {
            super();
        }
        
        //--------------------------------------------------------------------------
        //
        //  Variables
        //
        //--------------------------------------------------------------------------
        
        private var clickOffset:Point;
        
        //--------------------------------------------------------------------------
        //
        //  Properties 
        //
        //--------------------------------------------------------------------------
        
        //----------------------------------
        //  Resize Handle
        //---------------------------------- 
        
        [("false")]
        
        /**
         *  The skin part that defines the area where
         *  the user may drag to resize the window.
         */
        public var resizeHandle:UIComponent;
        
        //--------------------------------------------------------------------------
        //
        //  Overridden methods: UIComponent, SkinnableComponent
        //
        //--------------------------------------------------------------------------
        
        /**
         *  @private
         */
        override protected function partAdded(partName:String, instance:Object) : void
        {
            super.partAdded(partName, instance);
            
            if (instance == resizeHandle)
            {
                resizeHandle.addEventListener(MouseEvent.MOUSE_DOWN, resizeHandle_mouseDownHandler);
            }
        }
        
        /**
         *  @private
         */
        override protected function partRemoved(partName:String, instance:Object):void
        {
            if (instance == resizeHandle)
            {
                resizeHandle.removeEventListener(MouseEvent.MOUSE_DOWN, resizeHandle_mouseDownHandler);
            }
            
            super.partRemoved(partName, instance);
        }
        
        //--------------------------------------------------------------------------
        // 
        // Event Handlers
        //
        //--------------------------------------------------------------------------
        
        private var prevWidth:Number;
        private var prevHeight:Number;
        
        protected function resizeHandle_mouseDownHandler(event:MouseEvent):void
        {
            if (enabled && isPopUp && !clickOffset)
            {        
                clickOffset = new Point(event.stageX, event.stageY);
                prevWidth = width;
                prevHeight = height;
                
                var sbRoot:DisplayObject = systemManager.getSandboxRoot();
                
                sbRoot.addEventListener(
                    MouseEvent.MOUSE_MOVE, resizeHandle_mouseMoveHandler, true);
                sbRoot.addEventListener(
                    MouseEvent.MOUSE_UP, resizeHandle_mouseUpHandler, true);
                sbRoot.addEventListener(
                    SandboxMouseEvent.MOUSE_UP_SOMEWHERE, resizeHandle_mouseUpHandler)
            }
        }
        
        /**
         *  @private
         */
        protected function resizeHandle_mouseMoveHandler(event:MouseEvent):void
        {
            // during a resize, only the TitleWindow should get mouse move events
            // 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 resize.
            event.stopImmediatePropagation();
            
            if (!clickOffset)
            {
                return;
            }
            
            width = prevWidth + (event.stageX - clickOffset.x);
            height = prevHeight + (event.stageY - clickOffset.y);
            event.updateAfterEvent();
        }
        
        /**
         *  @private
         */
        protected function resizeHandle_mouseUpHandler(event:Event):void
        {
            clickOffset = null;
            prevWidth = NaN;
            prevHeight = NaN;
            
            var sbRoot:DisplayObject = systemManager.getSandboxRoot();
            
            sbRoot.removeEventListener(
                MouseEvent.MOUSE_MOVE, resizeHandle_mouseMoveHandler, true);
            sbRoot.removeEventListener(
                MouseEvent.MOUSE_UP, resizeHandle_mouseUpHandler, true);
            sbRoot.removeEventListener(
                SandboxMouseEvent.MOUSE_UP_SOMEWHERE, resizeHandle_mouseUpHandler);
        }
    }
}
打包下载地址:http://flexponential.com/samples/ResizableTitleWindow/srcview/ResizableTitleWindow.zip

From: http://flexponential.com/2010/01/10/resizable-titlewindow-in-flex-4/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值