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

3 of 9

Basic Frame Scripting on Load, createEmptyMovieClip, Mouse Listeners
Deconstructing the Paint Application II: The Brush Tool & the Flash Drawing API
With the brush cursor finished, return to your main stage, create a layer for your Actions, create an empty keyframe, and then right-click that keyframe and select Actions.
_root.brushcursor.swapDepths(12) ;

This just uses swapDepths to make sure that the brush cursor is set at a depth level well above anything else that we might create, so that nothing overlaps and conceals it.

_root.createEmptyMovieClip(“drawing”,0) ;

createEmptyMovieClip is a function that, as the name implies, creates an empty movie clip on the stage. You can use it inside an onClipEvent handler or several other handlers; in this case we’ve just assigned it to the Actions of the first frame of the movie so that the movie clip is created the moment that it loads. The parameters of createEmptyMovieClip are the instance name and depth; specify the instance name inside quotes, and the depth as an integer to determine its stacking order with other objects in the movie.

We’re using this as a container for our drawings. Everything that’s drawn at depth 0 using the brush tool or any other tool will be created inside this empty movie clip.

_root.onMouseUp = function() { 
_root.onMouseMove = stoppit; 
}

This is a listener; a listener “listens” for specified mouse actions at the root level. This listener listens for the left mouse button to be released, and then performs the action inside the function. The currently specified action is to stop whatever is happening when the mouse is moving (such as painting) when the mouse button is released, so that it doesn’t keep painting even when you stop dragging the depressed mouse cursor.

©2014 About.com. All rights reserved.