加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

直角连接线

发布时间:2020-12-15 04:11:06 所属栏目:百科 来源:网络整理
导读:这是一个线条类 package aline{import aaRight.RectHandle;import aaRight.RectHandle;import aaRight.RectHandle;import aaRight.RectHandle;import aaRight.RectHandle;import flash.events.Event;import flash.events.MouseEvent;import flash.geom.Point

这是一个线条类

package aline
{
	import aaRight.RectHandle;
	import aaRight.RectHandle;
	import aaRight.RectHandle;
	import aaRight.RectHandle;
	import aaRight.RectHandle;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import maodian.BrokenLineRect;
	
	import mx.core.UIComponent;
	
	public class LineAngle extends UIComponent
		
	{
		public var startPoint:Point;           //起启节点
		public var endPoint:Point;             //结束节点、
		public var isArrow:Boolean = true;       //是否有箭头
		public var arrowSize:uint = 6;           //箭头大小
		public var lineColor:uint = 0x000000;       //颜色
		public var tip:String = "线条";          //提示语
		
		
		private var _firstRect:BrokenLineRect;  
		private var _secondRect:BrokenLineRect;  
		private var _thirdRect:BrokenLineRect; 
		private var _rect_w:Number = 6;   
		
		public function LineAngle()
		{
			super();
		}
		
		public function drawLine():void
		{                   //************还要扩展,扩展成能够拉的折线的,参考UXine**********
			this.graphics.clear();
			this.graphics.lineStyle(2,lineColor);
			this.graphics.moveTo(startPoint.x,startPoint.y);
			this.graphics.lineTo(endPoint.x,endPoint.y);
			this.toolTip = tip;
//--------------------------------------------------------------------------------------------------------
	//增加锚点的
			_firstRect = new BrokenLineRect();                    //画线的时候,就建立了三个锚点,一条边
			_secondRect = new BrokenLineRect();  
			_thirdRect = new BrokenLineRect();  
			
			initFirstRect();  
			initSecondRect();  
			initThirdRect();  
			
			addChild(_firstRect);  
			addChild(_thirdRect);  
			addChild(_secondRect);
//--------------------------------------------------------------------------------------------------------
	//画箭头
			if(isArrow){
				
				var angle:Number  = this.getAngle();
				var centerX:Number = endPoint.x - arrowSize * Math.cos(angle*(Math.PI/180));
				var centerY:Number = endPoint.y + arrowSize * Math.sin(angle*(Math.PI/180));
				
				
				var leftX:Number = centerX + arrowSize * Math.cos((angle+120)*(Math.PI/180));
				var leftY:Number = centerY - arrowSize * Math.sin((angle+120)*(Math.PI/180));
				var rightX:Number = centerX + arrowSize * Math.cos((angle+240)*(Math.PI/180));
				var rightY:Number = centerY - arrowSize * Math.sin((angle+240)*(Math.PI/180));
				
				//this.graphics.beginFill(lineColor,1);
				
				this.graphics.lineStyle(2,lineColor,1);
				this.graphics.moveTo(endPoint.x,endPoint.y);
				
				this.graphics.lineTo(leftX,leftY);
				this.graphics.lineTo(centerX,centerY);
				
				this.graphics.lineTo(rightX,rightY);
				this.graphics.lineTo(endPoint.x,endPoint.y);
				//this.graphics.endFill();
			}
		}
		
//得到线的角度
		public function getAngle():Number
		{
			var temX:Number = endPoint.x - startPoint.x;
			var temY:Number = startPoint.y - endPoint.y;
			var angle:Number = Math.atan2(temY,temX)*(180/Math.PI)
			return angle;
		}
		
		//删除
		public function removeLine():void
		{
			this.graphics.clear();
		}
		

//----------------------------------------------
		
		/**初始化第一个端点的矩形*/  
		public function initFirstRect():void
		{  
			_firstRect.width = _rect_w;  
			_firstRect.height = _rect_w;  
			_firstRect.x =startPoint.x - _firstRect.width;  
			_firstRect.y = startPoint.y - _firstRect.height/2;  
			_firstRect.setStyle("borderColor","#70B2EE");  
			_firstRect.desc = "_firstRect";  
//			addRectEvent(_firstRect); 
	}
		
		/**初始化中点矩形*/  
		public function initThirdRect():void
		{  
			_thirdRect.width = _rect_w;  
			_thirdRect.height = _rect_w;  
			_thirdRect.setStyle("borderColor","#70B2EE");  
			_thirdRect.x = (_firstRect.x + _secondRect.x)/2;  
			_thirdRect.y = (_firstRect.y + _secondRect.y)/2;  
			_thirdRect.desc = "_thirdRect";  
//			addRectEvent(_thirdRect);  
		}  
		
		/**初始化第二个端点的矩形*/  
		public function initSecondRect():void
		{  
			_secondRect.width = _rect_w;  
			_secondRect.height = _rect_w;  
			_secondRect.x = endPoint.x;  
			_secondRect.y = endPoint.y - _secondRect.height/2;  
			_secondRect.setStyle("borderColor","#70B2EE");  
			_secondRect.desc = "_secondRect";  
//			addRectEvent(_secondRect);  
		} 
		
		
// 直角线的画出来	
		
		public var XPoint:Point = new Point();
//-------------------------------------------------------------------------------------------
		public function draw2Line(pointX:int,pointY:int):void
			{             //还应该判断起始点,确定线段和箭头的
			
			XPoint.x = pointX;
			XPoint.y = pointY;
			
			this.graphics.clear();  
			//			this.graphics.lineStyle(_lineStyle,_lineColor,1);   
			this.graphics.lineStyle(2,lineColor);   
			this.graphics.moveTo(startPoint.x,startPoint.y);  
			this.graphics.lineTo(pointX,pointY);  
			this.graphics.moveTo(pointX,pointY);
			this.graphics.lineTo(endPoint.x,endPoint.y);  
			this.toolTip = tip;
			
			
			if(isArrow){
				
				var angle:Number  = this.get2Angle(pointX,pointY);
				var centerX:Number = endPoint.x - arrowSize * Math.cos(angle * (Math.PI/180));
				var centerY:Number = endPoint.y + arrowSize * Math.sin(angle * (Math.PI/180));
				
				
				var leftX:Number = centerX + arrowSize * Math.cos((angle+120) * (Math.PI/180));
				var leftY:Number = centerY - arrowSize * Math.sin((angle+120) * (Math.PI/180));
				var rightX:Number = centerX + arrowSize * Math.cos((angle+240) * (Math.PI/180));
				var rightY:Number = centerY - arrowSize * Math.sin((angle+240) * (Math.PI/180));
				
				
				this.graphics.lineStyle(2,endPoint.y);
			}
		}
//控制中间点与终点的角度来计算角度
		public function get2Angle(pointX:Number,pointY:Number):Number
		{
			var temX:Number = endPoint.x - pointX;
			var temY:Number = pointY - endPoint.y;
			var angle:Number = Math.atan2(temY,temX) * (180/Math.PI);
			return angle;
		}
		
//---------------------------------------------------------------------------------------------------------
		public var _oneRect:RectHandle;
		public var _twoRect:RectHandle;
		public var _threeRect:RectHandle;		   //连线交叉点,拐点,可以任意方向	
		public var _fourRect:RectHandle;            //2和4都是中间的点的,只有上下,左右方向
		public var _fiveRect:RectHandle;            //1和5一样,起终点,拉长短
		
		public function createRole():void
		{
			_oneRect = new RectHandle();
			_twoRect = new RectHandle();
			_threeRect = new RectHandle();
			_fourRect = new RectHandle();
			_fiveRect = new RectHandle();          //这是静态加进去的,动态怎么加进去的呢?????好像是objectHandles解决的??
			
			initOneRect();
			initTwoRect();
			initThreeRect();
			initFourRect();
			initFiveRect();
			
			addChild(_oneRect);
			addChild(_twoRect);
			addChild(_threeRect);
			addChild(_fourRect);
			addChild(_fiveRect);
		}
		
		public function initOneRect():void
		{                     //第一个点的,起始
			_oneRect.width = 6;
			_oneRect.height = 6;
			_oneRect.x = startPoint.x - _oneRect.width/2;
			_oneRect.y = startPoint.y-_oneRect.height/2;
		}
		
		public function initTwoRect():void
		{
			_twoRect.width = 6;
			_twoRect.height = 6;
			_twoRect.x = (XPoint.x+startPoint.x)/2 - _twoRect.width/2;
			_twoRect.y = (XPoint.y+startPoint.y)/2 - _twoRect.height/2;
		}
		
		public function initThreeRect():void
		{
			_threeRect.width = 6;
			_threeRect.height = 6;
			_threeRect.x = XPoint.x - _threeRect.width/2;
			_threeRect.y = XPoint.y - _threeRect.height/2;
		}
		
		public function initFourRect():void
		{
			_fourRect.width = 6;
			_fourRect.height = 6;
			_fourRect.x = (XPoint.x+endPoint.x)/2 - _fourRect.width/2;
			_fourRect.y = (XPoint.y+endPoint.y)/2 - _fourRect.height/2;
		}
		
		public function initFiveRect():void
		{
			_fiveRect.width = 6;
			_fiveRect.height = 6;
			_fiveRect.x = endPoint.x - _fiveRect.width/2;
			_fiveRect.y = endPoint.y - _fiveRect.height/2;
		}
		
	}
}


这是应用的

<?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="init()">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import aline.LineAngle;
			
			public function init():void
			{
				containBC.addEventListener(MouseEvent.MOUSE_DOWN,rightAngleMouseDown);
			}
			
			public var savePoint:Array = new Array(); 				//存储点的数组
			public var saveLine:LineAngle = null;					//存储线的数组
			public var lineAngle:LineAngle;            		  
			
			public function rightAngleMouseDown(event:MouseEvent):void
			{
				
				trace(event.target + ".." + event.currentTarget);
				
				if(event.target is RectHandle){                          //锚点          mouseChild和hostComponent
					trace("this twoRect" + this);
					this.addEventListener(MouseEvent.MOUSE_MOVE,_twoRectMoveHandle);
					this.addEventListener(MouseEvent.MOUSE_UP,_twoRectUpHandle);
					
				}else if(event.target is LineAngle)					 //线条
				{
					trace("this lineAngle" + this);
					lineAngle = event.target as LineAngle;
					
					lineAngle.addEventListener(MouseEvent.MOUSE_MOVE,LineAngleMove);
					lineAngle.addEventListener(MouseEvent.MOUSE_UP,LineAngleUp);
					
				}else
				{		
					lineAngle = new LineAngle();
					lineAngle.startPoint = new Point(event.stageX,event.stageY);                //(30,100)
					lineAngle.endPoint = new Point(event.stageX,event.stageY);
					
					trace("this else" + this);
					this.addEventListener(MouseEvent.MOUSE_MOVE,rightAngleMouseMove);
					this.addEventListener(MouseEvent.MOUSE_UP,rightAngleMouseUp);
					
				}
			}
			
			public function LineAngleMove(event:MouseEvent):void
			{
				//				event.stopImmediatePropagation();
				trace(this);
				lineAngle.startDrag();
			}
			
			public function LineAngleUp(event:MouseEvent):void
			{
				lineAngle.stopDrag();
				lineAngle.removeEventListener(MouseEvent.MOUSE_MOVE,LineAngleMove);
				lineAngle.removeEventListener(MouseEvent.MOUSE_UP,LineAngleUp);
			}
			
			public var firstPoint:Point = new Point();
			public var lineList:Array = new Array();
			public var currentLine:int = 0;
			public function rightAngleMouseMove(event:MouseEvent):void
			{
				//-------------------------------------------------------------------------------------------	
				if(event.stageX >= lineAngle.startPoint.x && event.stageY < lineAngle.startPoint.y)
				{   
					//一象限,此时箭头就不是两点时的箭头了,方向是水平或者垂直
					trace('x增加,y轴减少');
					
					if(lineAngle.getAngle() >= 45 && lineAngle.getAngle() <= 90)
					{
						firstPoint.x = lineAngle.startPoint.x;
						firstPoint.y = event.stageY;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)  
					}
					
					if(lineAngle.getAngle() >= 0 && lineAngle.getAngle() <= 45)
					{
						firstPoint.x = event.stageX;
						firstPoint.y = lineAngle.startPoint.y;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)
					}
				}else if(event.stageX >= lineAngle.startPoint.x && event.stageY>lineAngle.startPoint.y)
				{   																 //四象限
					trace('x增加,y轴增加');
					
					if(lineAngle.getAngle() >= -90 && lineAngle.getAngle() <= -45)
					{
						firstPoint.x = lineAngle.startPoint.x;
						firstPoint.y = event.stageY;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)  
					}else if(lineAngle.getAngle() >= -45 && lineAngle.getAngle() <= 0)
					{
						firstPoint.x = event.stageX;
						firstPoint.y = lineAngle.startPoint.y;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)
					}
				}
				else if(event.stageX <= lineAngle.startPoint.x && event.stageY < lineAngle.startPoint.y)
				{   																	 //二象限
					trace('x减少,y轴减少');
					
					if(lineAngle.getAngle() >= 90 && lineAngle.getAngle() <= 135)
					{
						firstPoint.x = lineAngle.startPoint.x;
						firstPoint.y = event.stageY;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)  
						
					}else if(lineAngle.getAngle() >= 135 && lineAngle.getAngle() <= 180)
					{
						firstPoint.x = event.stageX;
						firstPoint.y = lineAngle.startPoint.y;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)
						
					}
				}
				else if(event.stageX <= lineAngle.startPoint.x && event.stageY>lineAngle.startPoint.y)
				{  																  //三象限
					trace('x减少,y轴增加');
					
					if(lineAngle.getAngle() >= -135 && lineAngle.getAngle() <= -90)
					{
						firstPoint.x=lineAngle.startPoint.x;
						firstPoint.y=event.stageY;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)  
					}
					
					if(lineAngle.getAngle() >= -180 && lineAngle.getAngle() <= -135)
					{
						firstPoint.x = event.stageX;
						firstPoint.y = lineAngle.startPoint.y;
						savePoint.push(firstPoint);                         //折点放到数组里面去(30,20)
					}
				}else
				{
					//没有移动的时候
				}
				
				lineAngle.endPoint = new Point(event.stageX,event.stageY);
				//-------------------------------------------------------------------------------------------	
				lineAngle.draw2Line(firstPoint.x,firstPoint.y);
				containBC.addElement(lineAngle);
			}
			
			public function rightAngleMouseUp(event:MouseEvent):void
			{
				lineAngle.createRole();
				this.removeEventListener(MouseEvent.MOUSE_MOVE,rightAngleMouseMove);
				this.removeEventListener(MouseEvent.MOUSE_UP,rightAngleMouseUp);
			}
			
			//----加节点和锚点都在下面了----------------------------------------------------------------------------------
			
			public var saveTwoPoint:Point = new Point()
			
			public function _twoRectMoveHandle(event:MouseEvent):void
			{
				trace("rectMove");
				event.stopImmediatePropagation();
																			//分为好多种情况来完成的,水平的时候
				if((lineAngle.startPoint.y) == firstPoint.y){                     
					trace("_twoRect Move,水平");
					lineAngle.startPoint.y = event.stageY;
					firstPoint.y = event.stageY;
					trace(firstPoint.x,firstPoint.y);
					lineAngle.draw2Line(firstPoint.x,firstPoint.y);
				}
				
																			//垂直的时候					
				if((lineAngle.startPoint.x) == firstPoint.x){                      
					trace("_twoRect Move,垂直");
					lineAngle.startPoint.x = event.stageX;
					firstPoint.x = event.stageX;
					trace(firstPoint.x,firstPoint.y);
				}
				containBC.addElement(lineAngle);
			}
			public function _twoRectUpHandle(event:MouseEvent):void
			{
				lineAngle.createRole();
				this.removeEventListener(MouseEvent.MOUSE_MOVE,_twoRectMoveHandle);
				this.removeEventListener(MouseEvent.MOUSE_UP,_twoRectUpHandle);
			}
			//--------------————————————————————————————————————————————------
		]]>
	</fx:Script>
	<s:BorderContainer id="containBC" width="400" height="400"/>
</s:Application>


这是role类

package aaRight
{
?? ?import flash.events.Event;
?? ?import flash.events.MouseEvent;
?? ?
?? ?import spark.components.BorderContainer;

?? ?public class RectHandle extends BorderContainer
?? ?{
?? ??? ?public function RectHandle()
?? ??? ?{
?? ??? ??? ?super();
?? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_DOWN,_twoRectDownHandle);
?? ??? ??? ?this.mouseChildren=false;
?? ??? ?}
?? ??? ?
?? ??? ?public function _twoRectDownHandle(event:MouseEvent):void
?? ??? ?{
?? ??? ??? ?trace("RectHandle");
?? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_MOVE,_twoRectMoveHandle);
?? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_UP,_twoRectUpHandle);
?? ??? ?}
?? ??? ?public function _twoRectMoveHandle(event:MouseEvent):void
?? ??? ?{
?? ??? ??? ?
?? ??? ?}
?? ??? ?public function _twoRectUpHandle(event:MouseEvent):void
?? ??? ?{
?? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_MOVE,_twoRectMoveHandle);
?? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_UP,_twoRectUpHandle);
?? ??? ?}
?? ?}
}

?

新的类

<?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="init()"> ?? ?<fx:Declarations> ?? ??? ?<!-- 将非可视元素(例如服务、值对象)放在此处 --> ?? ?</fx:Declarations> ?? ?<fx:Script> ?? ??? ?<![CDATA[ ?? ??? ??? ?import aline.LineAngle; ?? ??? ??? ? ?? ??? ??? ?import mx.collections.ArrayList; ?? ??? ??? ? ?? ??? ??? ?public function init():void ?? ??? ??? ?{ ?? ??? ??? ??? ?containBC.addEventListener(MouseEvent.MOUSE_DOWN,rightAngleMouseDown); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public var savePoint:Array = new Array(); ?? ??? ??? ??? ?//存储点的数组 ?? ??? ??? ?public var saveLine:LineAngle = null;?? ??? ??? ??? ??? ?//存储线的数组 ?? ??? ??? ?public var lineAngle:LineAngle;? ? ?? ??? ??? ?public var saveItem:ArrayList=new ArrayList(); ?? ??? ??? ? ?? ??? ??? ?public function rightAngleMouseDown(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?trace(event.target + ".." + event.currentTarget); ?? ??? ??? ??? ? ?? ??? ??? ??? ?if(event.target is RectHandle){????????????????????????? //锚点????????? mouseChild和hostComponent ?? ??? ??? ??? ??? ?trace("this twoRect" + this); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(event.target.id == "_rect0" || event.target.id == "_rect3") ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_MOVE,LineRectMoveHandle); ?? ??? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_UP,LineRectUpHandle); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?}else if(event.target.id == "_rect1" || event.target.id == "_rect4") ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_MOVE,LineRect1MoveHandle); ?? ??? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_UP,LineRect1UpHandle); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?}else if(event.target.id == "_rect2" || event.target.id == "_rect5") ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_MOVE,LineRect2MoveHandle); ?? ??? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_UP,LineRect2UpHandle); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?}else if(event.target is LineAngle)?? ??? ??? ??? ??? ? //线条 ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?trace("this lineAngle" + this); ?? ??? ??? ??? ??? ?lineAngle = event.target as LineAngle; ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?lineAngle.addEventListener(MouseEvent.MOUSE_MOVE,LineAngleMove); ?? ??? ??? ??? ??? ?lineAngle.addEventListener(MouseEvent.MOUSE_UP,LineAngleUp); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ?}else ?? ??? ??? ??? ?{?? ??? ? ?? ??? ??? ??? ??? ?lineAngle = new LineAngle(); ?? ??? ??? ??? ??? ?lineAngle.startPoint = new Point(event.stageX,event.stageY);??????????????? //(30,100) ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?lineAngle.endPoint = new Point(event.stageX,event.stageY); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?trace("this else" + this); ?? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_MOVE,rightAngleMouseMove); ?? ??? ??? ??? ??? ?this.addEventListener(MouseEvent.MOUSE_UP,rightAngleMouseUp); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public function LineAngleMove(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?//?? ??? ??? ??? ?event.stopImmediatePropagation(); ?? ??? ??? ??? ?trace(this); ?? ??? ??? ??? ?lineAngle.startDrag(); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public function LineAngleUp(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?lineAngle.stopDrag(); ?? ??? ??? ??? ?lineAngle.removeEventListener(MouseEvent.MOUSE_MOVE,LineAngleMove); ?? ??? ??? ??? ?lineAngle.removeEventListener(MouseEvent.MOUSE_UP,LineAngleUp); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public var firstPoint:Point = new Point(); ?? ??? ??? ?public var lineList:Array = new Array(); ?? ??? ??? ?public var currentLine:int = 0; ?? ??? ??? ?public function rightAngleMouseMove(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?//-------------------------------------------------------------------------------------------?? ? ?? ??? ??? ??? ?if(event.stageX >= lineAngle.startPoint.x && event.stageY < lineAngle.startPoint.y) ?? ??? ??? ??? ?{? ? ?? ??? ??? ??? ??? ?//一象限,此时箭头就不是两点时的箭头了,方向是水平或者垂直 ?? ??? ??? ??? ??? ?trace('x增加,y轴减少'); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(lineAngle.getAngle() >= 45 && lineAngle.getAngle() <= 90) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = lineAngle.startPoint.x; ?? ??? ??? ??? ??? ??? ?firstPoint.y = event.stageY; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(lineAngle.getAngle() >= 0 && lineAngle.getAngle() <= 45) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = event.stageX; ?? ??? ??? ??? ??? ??? ?firstPoint.y = lineAngle.startPoint.y; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?}else if(event.stageX >= lineAngle.startPoint.x && event.stageY>lineAngle.startPoint.y) ?? ??? ??? ??? ?{? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? //四象限 ?? ??? ??? ??? ??? ?trace('x增加,y轴增加'); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(lineAngle.getAngle() >= -90 && lineAngle.getAngle() <= -45) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = lineAngle.startPoint.x; ?? ??? ??? ??? ??? ??? ?firstPoint.y = event.stageY; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ? ?? ??? ??? ??? ??? ?}else if(lineAngle.getAngle() >= -45 && lineAngle.getAngle() <= 0) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = event.stageX; ?? ??? ??? ??? ??? ??? ?firstPoint.y = lineAngle.startPoint.y; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else if(event.stageX <= lineAngle.startPoint.x && event.stageY < lineAngle.startPoint.y) ?? ??? ??? ??? ?{? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? //二象限 ?? ??? ??? ??? ??? ?trace('x减少,y轴减少'); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(lineAngle.getAngle() >= 90 && lineAngle.getAngle() <= 135) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = lineAngle.startPoint.x; ?? ??? ??? ??? ??? ??? ?firstPoint.y = event.stageY; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ? ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?}else if(lineAngle.getAngle() >= 135 && lineAngle.getAngle() <= 180) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = event.stageX; ?? ??? ??? ??? ??? ??? ?firstPoint.y = lineAngle.startPoint.y; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else if(event.stageX <= lineAngle.startPoint.x && event.stageY>lineAngle.startPoint.y) ?? ??? ??? ??? ?{ ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?? //三象限 ?? ??? ??? ??? ??? ?trace('x减少,y轴增加'); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(lineAngle.getAngle() >= -135 && lineAngle.getAngle() <= -90) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x=lineAngle.startPoint.x; ?? ??? ??? ??? ??? ??? ?firstPoint.y=event.stageY; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(lineAngle.getAngle() >= -180 && lineAngle.getAngle() <= -135) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?firstPoint.x = event.stageX; ?? ??? ??? ??? ??? ??? ?firstPoint.y = lineAngle.startPoint.y; ?? ??? ??? ??? ??? ??? ?savePoint.push(firstPoint);???????????????????????? //折点放到数组里面去(30,20) ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?}else ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?//没有移动的时候 ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?lineAngle.endPoint = new Point(event.stageX,event.stageY); ?? ??? ??? ??? ?//-------------------------------------------------------------------------------------------?? ? ?? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ?containBC.addElement(lineAngle); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public var rectHand:RectHandle; ?? ??? ??? ?public function rightAngleMouseUp(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?createHandles(); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_MOVE,rightAngleMouseMove); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_UP,rightAngleMouseUp); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?//----加节点和锚点都在下面了---------------------------------------------------------------------------------- ?? ??? ??? ? ?? ??? ??? ?public var saveTwoPoint:Point = new Point() ?? ??? ??? ? ?? ??? ??? ?public function LineRectMoveHandle(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?trace("rectMove"+event.target);?????????????????????????????? //拖动,删除线条上的节点,释放,又添加节点 //垂直的时候?? ? 四中情况 ?? ??? ??? ??? ?removeHandles(); ?? ??? ??? ??? ? ?? ??? ??? ??? ?if((lineAngle.startPoint.y) == firstPoint.y && (lineAngle.endPoint.x) == firstPoint.x){???? ? ?? ??? ??? ??? ??? ?trace("LineRect Move,水平"); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ?lineAngle.startPoint.x = event.stageX; ?? ??? ??? ??? ??? ??? ?lineAngle.startPoint.y = event.stageY; ?? ??? ??? ??? ??? ??? ?firstPoint.y = lineAngle.startPoint.y; ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ?}else if((lineAngle.startPoint.x) == firstPoint.x && (lineAngle.endPoint.y) == firstPoint.y) ?? ??? ??? ??? ?{???????????????????? ? ?? ??? ??? ??? ??? ?trace("LineRect Move,垂直"); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?lineAngle.startPoint.x = event.stageX; ?? ??? ??? ??? ??? ?lineAngle.startPoint.y = event.stageY; ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?firstPoint.x = lineAngle.startPoint.x; ?? ??? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?containBC.addElement(lineAngle); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public function LineRectUpHandle(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?trace(lineAngle.startPoint+"::"+firstPoint+"::"+lineAngle.endPoint) ?? ??? ??? ??? ?createHandles(); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_MOVE,LineRectMoveHandle); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_UP,LineRectUpHandle); ?? ??? ??? ?} //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- ?? ??? ??? ?public function LineRect1MoveHandle(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?trace("rectMove"+event.target); ?? ??? ??? ??? ?removeHandles(); ?? ??? ??? ??? ? ?? ??? ??? ??? ?if((lineAngle.startPoint.y) == firstPoint.y && (lineAngle.endPoint.x) == firstPoint.x) ?? ??? ??? ??? ?{?? //四中情况出现????? ? ?? ??? ??? ??? ??? ?trace("LineRect Move,水平"); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?firstPoint.x = event.stageX; ?? ??? ??? ??? ??? ?firstPoint.y = event.stageY; ?? ??? ??? ??? ??? ?lineAngle.startPoint.y = firstPoint.y; ?? ??? ??? ??? ??? ?lineAngle.endPoint.x = firstPoint.x; ?? ??? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?//垂直的时候?? ? 四中情况 ?? ??? ??? ??? ? ?? ??? ??? ??? ?if((lineAngle.startPoint.x) == firstPoint.x && (lineAngle.endPoint.y) == firstPoint.y) ?? ??? ??? ??? ?{???????????????????? ? ?? ??? ??? ??? ??? ?trace("LineRect Move,垂直"); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?firstPoint.x = event.stageX; ?? ??? ??? ??? ??? ?firstPoint.y = event.stageY; ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?lineAngle.startPoint.x = firstPoint.x; ?? ??? ??? ??? ??? ?lineAngle.endPoint.y = firstPoint.y; ?? ??? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?containBC.addElement(lineAngle); ?? ??? ??? ?} ?? ??? ??? ?public function LineRect1UpHandle(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?createHandles(); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_MOVE,LineRect1MoveHandle); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_UP,LineRect1UpHandle); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public function LineRect2MoveHandle(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?trace("rectMove"+event.target); ?? ??? ??? ??? ?removeHandles(); ?? ??? ??? ??? ? ?? ??? ??? ??? ?if((lineAngle.startPoint.y) == firstPoint.y && (lineAngle.endPoint.x) == firstPoint.x) ?? ??? ??? ??? ?{?? //四中情况出现????? ? ?? ??? ??? ??? ??? ?trace("LineRect Move,水平"); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?lineAngle.endPoint.x = event.stageX; ?? ??? ??? ??? ??? ?lineAngle.endPoint.y = event.stageY; ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?firstPoint.x = lineAngle.endPoint.x; ?? ??? ??? ??? ??? ?trace(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?//垂直的时候?? ? 四中情况 ?? ??? ??? ??? ? ?? ??? ??? ??? ?if((lineAngle.startPoint.x) == firstPoint.x && (lineAngle.endPoint.y) == firstPoint.y) ?? ??? ??? ??? ?{???????????????????? ? ?? ??? ??? ??? ??? ?trace("LineRect Move,垂直"); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?lineAngle.endPoint.x = event.stageX; ?? ??? ??? ??? ??? ?lineAngle.endPoint.y = event.stageY; ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?firstPoint.y = lineAngle.endPoint.y; ?? ??? ??? ??? ??? ?lineAngle.draw2Line(firstPoint.x,firstPoint.y); ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?containBC.addElement(lineAngle); ?? ??? ??? ?} ?? ??? ??? ?public function LineRect2UpHandle(event:MouseEvent):void ?? ??? ??? ?{ ?? ??? ??? ??? ?createHandles(); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_MOVE,LineRect2MoveHandle); ?? ??? ??? ??? ?this.removeEventListener(MouseEvent.MOUSE_UP,LineRect2UpHandle); ?? ??? ??? ?} //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- ?? ??? ??? ?public function createHandles():void{??????????????????????? //要实现重用,第一次还好,后面就不行了,后面的怎么用啊??? ?? ??? ??? ??? ?saveItem.removeAll();?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ?saveItem.addItem(lineAngle.startPoint); ?? ??? ??? ??? ?saveItem.addItem(firstPoint); ?? ??? ??? ??? ?saveItem.addItem(lineAngle.endPoint); ?? ??? ??? ??? ?for (var i:int = 0; i < saveItem.length; i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?trace(saveItem.getItemAt(i) + "000000"); ?? ??? ??? ??? ??? ?rectHand = new RectHandle(); ?? ??? ??? ??? ??? ?rectHand.id = "_rect"+i;?????????????????????????????? //生成的锚点名字分别为_rect0,_rect1,_rect2 ?? ??? ??? ??? ??? ?rectHand.x = (saveItem.getItemAt(i) as Point).x; ?? ??? ??? ??? ??? ?rectHand.y = (saveItem.getItemAt(i) as Point).y; ?? ??? ??? ??? ??? ?lineAngle.addChild(rectHand); ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?public function removeHandles():void ?? ??? ??? ?{ ?? ??? ??? ??? ?for (var i:int = 0; i < lineAngle.numChildren; i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?trace(lineAngle.numChildren+"//"+lineAngle.getChildAt(i)); ?? ??? ??? ??? ??? ?lineAngle.removeChildAt(i); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?trace(lineAngle.numChildren); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ?]]> ?? ?</fx:Script> ?? ?<s:BorderContainer id="containBC" width="400" height="400"/> </s:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读