• Flex Air TitleWindow 拖动范围控制


        在flex里面TitleWindow的拖动范围默认是不控制的,但是我们经常需要将其约束在整个应用程序的主窗口内,我找了半天也没有找到相关属性设置,只能重写,下面是重写的代码:

        

    		override protected function startDragging(event:MouseEvent):void
    		{
    			regX = event.stageX - x;
    			regY = event.stageY - y;
    			
    			var sbRoot:DisplayObject = systemManager.getSandboxRoot();
    			sbRoot.addEventListener(
    				MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);
    			
    			sbRoot.addEventListener(
    				MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);
    			
    			sbRoot.addEventListener(
    				SandboxMouseEvent.MOUSE_UP_SOMEWHERE, stage_mouseLeaveHandler);
    			
    			// add the mouse shield so we can drag over untrusted applications.
    			systemManager.deployMouseShields(true);
    		}
    		
    		protected override function stopDragging():void
    		{
    			var sbRoot:DisplayObject = systemManager.getSandboxRoot();
    			sbRoot.removeEventListener(
    				MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);
    			
    			sbRoot.removeEventListener(
    				MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);
    			
    			sbRoot.removeEventListener(
    				SandboxMouseEvent.MOUSE_UP_SOMEWHERE, stage_mouseLeaveHandler);
    			
    			regX = NaN;
    			regY = NaN;
    			
    			systemManager.deployMouseShields(false);
    		}
    		
    		private function systemManager_mouseMoveHandler(event:MouseEvent):void
    		{			
    			event.stopImmediatePropagation();
    			
    			if (isNaN(regX) || isNaN(regY))
    			{				
    				return;
    			}
    			
    			var x:Number = event.stageX - regX;
    			var y:Number = event.stageY - regY;
    			var maxX:Number = this.stage.nativeWindow.width - this.width;
    			var maxY:Number = this.stage.nativeWindow.height - this.height;
    
    			//超出范围 ,停止移动
    			if(x < 0) x = 0;
    			if(y < 0) y = 0;
    			if(x > maxX) x = maxX;
    			if(y > maxY) y = maxY;
    			
    			move(x, y);
    		}
    		
    		private function systemManager_mouseUpHandler(event:MouseEvent):void
    		{
    			// trace("systemManager_mouseUpHandler: " + event);
    			if (!isNaN(regX))
    				stopDragging();
    		}		
    		
    		private function stage_mouseLeaveHandler(event:Event):void
    		{
    			// trace("stage_mouseLeaveHandler: " + event);
    			if (!isNaN(regX))
    				stopDragging();
    		}
    		
    		//拖动相关
    		private var regX:Number;
    		private var regY:Number;
    

  • 相关阅读:
    MySQL 修改表结构
    mysql中Timestamp,time,datetime 区别
    ERROR 1018 (HY000): Can't read dir of './test/' (errno: 13)
    Jquery报错:Uncaught TypeError: ((m.event.special[e.origType] || (intermediate value)).handle || e.handler).apply is not a function
    Python之No module named setuptools 安装pip
    这个快压到底是什么逗比?
    文档批量格式化之word技能
    连八进制都不知道
    python的异常小结与assert
    python 中的input
  • 原文地址:https://www.cnblogs.com/alala666888/p/2038206.html
Copyright © 2020-2023  润新知