1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Deconstructing the Paint Application II: The Brush Tool & the Flash Drawing API

By

8 of 9

Defining Brush Behavior with Mouse Movement Using the Drawing API
Deconstructing the Paint Application II: The Brush Tool & the Flash Drawing API
An onClipEvent checking for mouse movement uses lineTo again to make the brush keep drawing:
onClipEvent (mouseMove) { 
	if (draw==true&&_root.base.helptabs._visible==false) { 
		if (_root.isactive=="brush"){ 
			_root.drawing.lineTo(_root._xmouse, _root._ymouse) ; 
		} 
}

Notice that the if statement checks to see if the help file is visible again; otherwise the user will also be drawing while clicking on navigable areas of the help tabs. You’ll see that instead of checking to see if the brush is the active tool, we’re instead checking to see if the variable defined in the previous statement is true or false, and only proceeding if it’s true. Otherwise the brush would draw even when the left mouse button wasn’t depressed, and you wouldn’t be able to move the mouse without leaving a zigzagging trail behind.

Since we already set the attributes of the line drawing in our last statement block and defined its starting point, all this relatively simple statement does is tell Flash that every time the mouse moves, a new line should be drawn from the previous position to the current position. This works on a frame-by-frame basis, allowing for variations as small as a single pixel in freehand drawing.

©2014 About.com. All rights reserved.