create dynamic line using graphics class


This class simply create a line using Graphics class lineTo and moveTo methods hope this will help someone


package 
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class drawLine extends Sprite 
	{
		// variable to hold graphics class instanve
		private var g:Graphics;
		
		public function drawLine():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			g = graphics
			// this will set line thickness from 1 to 4 and a random color
			g.lineStyle(int(Math.random() * 3) + 1, Math.random() * 0xff0000);
			// this will moves the current drawing position to (50,50)
			g.moveTo(50, 50);
			draw();
		}
		
		private function draw():void
		{
			//Draws a line from the current drawing position to (500, 500).
			g.lineTo(500, 500);
		}
		
	}
	
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s