Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 2

Using ActionScript to draw lines

This page contains 3 examples, each of which has its own FLA file to download. Each example draws lines using ActionScript.

Example 1 of 3: use the moveTo command to position the pen at the specified x-y position (the specified coordinate), then use the lineTo command to draw straight lines between specified coordinates:

Download the FLA file

// This draws lines with the specified coordinates:	

createDrawing = function() {
	var doodle = this.createEmptyMovieClip("myDoodle", 0);
	doodle.lineStyle(5, 0xffffff, 100);
	doodle.moveTo(10, 20);	
	
	doodle.lineTo(300,20);
	doodle.lineTo(300,40);
	doodle.lineTo(10,40);
	doodle.lineTo(10,60);
	doodle.lineTo(300,60);
	doodle.lineTo(300,80);
	doodle.lineTo(10,80);	
	doodle.lineTo(10,100);
	doodle.lineTo(300,100);
	doodle.lineTo(300,120);
	doodle.lineTo(10,120);
	doodle.lineTo(10,140);
	doodle.lineTo(300,140);
	doodle.lineTo(300,160);
	doodle.lineTo(10,160);	
}

createDrawing();

Example 2 of 3: use the moveTo command to position the pen at the specified x-y position (the specified coordinate), then use the lineTo command to draw vertical and horizontal lines at random places. The movie loops so you can see many different random line patterns:

Download the FLA file

// This draws lines that are random but vertical or horizontal:		

createDrawing = function() {
	var doodle = this.createEmptyMovieClip("myDoodle", 0);
	doodle.lineStyle(5, 0xffffff, 100);
	
	newX = 160;
	newY = 100;
	
	doodle.moveTo(newX,newY);
	
	for (i=0; i<30; i++)
	{
		newX = Math.random()*300;
		doodle.lineTo(newX,newY);
		
		newY = Math.random()*200;
		doodle.lineTo(newX,newY);					
	}	 
}

createDrawing();

Example 3 of 3: use the moveTo command to position the pen at the specified x-y position (the specified coordinate), then use the lineTo command to lines at random places and at any random angle. The movie loops so you can see many different random line patterns:

Download the FLA file

// This draws random lines at any angle:

createDrawing = function() {
	var doodle = this.createEmptyMovieClip("myDoodle", 0);
	doodle.lineStyle(5, 0xffffff, 100);	
	
	newX = 160;
	newY = 100;
	
	doodle.moveTo(newX,newY);
	
	for (i=0; i<30; i++)
	{
		newX = Math.random()*320;		
		newY = Math.random()*200;
		doodle.lineTo(newX,newY);					
	}	 
}

createDrawing();


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM