| Refresh | Home EGTry.com

draw line with linecap setting


linecap linecap

LineCap.as

package {
	import flash.display.CapsStyle;
	import flash.display.Graphics;
	import flash.display.LineScaleMode;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class LineCap extends Sprite
	{
		private var x1:int=20;
		private var x2:int=100;
		private var y1:int;
		private var g:Graphics;
		
		public function LineCap()
		{
			var shape:Shape=new Shape();
			g=shape.graphics;
			addChild(shape);
			
			y1=10;
			g.lineStyle(2,0xff0000);
			drawLine("lineStyle(2,0xff0000);");
			
			
		
			y1 +=20;	
			g.lineStyle(10,0x000000,1,false,LineScaleMode.NONE,CapsStyle.NONE);
			drawLine("line cap: "+CapsStyle.NONE);
			
			y1 +=20;
			g.lineStyle(10,0x000000,1,false,LineScaleMode.NONE,CapsStyle.SQUARE);
			drawLine("line cap: "+CapsStyle.SQUARE);
			
			y1 +=20;
			g.lineStyle(10,0x000000,1,false,LineScaleMode.NONE,CapsStyle.ROUND);
			drawLine("line cap: "+CapsStyle.ROUND);


			

			addChild(shape);
			
		}
		
		private function drawLine(text:String):void {
			g.moveTo(x1,y1);
			g.lineTo(x2,y1);
			
			var t:TextField=new TextField();
			t.x=x2+5;
			t.y=y1-5;
			t.width=200;
			t.text=text;
			addChild(t);
		}
	}
}