1. Home
  2. Computing & Technology
  3. Animation

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

By , About.com Guide

8 of 9

Defining Brush Behavior with Mouse Movement Using the 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.

Explore Animation
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Deconstructing the Paint Application II: The Brush Tool and the Flash Drawing API

©2009 About.com, a part of The New York Times Company.

All rights reserved.