Assembling the Flash Paint Application

You have now created all the necessary components for the Flash Paint application. The only remaining step is to create the main routine that puts them all together. To accomplish this, add the following code to the first frame of the main timeline of the flashPaint.fla document:

// Include MovieClip.as from Chapter 7, DrawingMethods.as from Chapter 4, and
// Table.as from Chapter 11 for their custom methods.
#include "MovieClip.as"
#include "DrawingMethods.as"
#include "Table.as"

// Initialize the movie.
function init(  ) {
  selectedShape = null;
  selectedTool = null;
  shapes = new Array(  );
  makeTools(  );
}

// The makeTools(  ) method creates the toolbar buttons.
function makeTools (  ) {

  // Define an array of the first six tool names. These names match the accepted
  // values within the toolbar button component.
  toolbarBtnNames = ["select", "line", "rectangle", "ellipse", "text", "fill"];

  // Create an array to hold references to the "stick" toolbar button instances.
  toolbarBtns = new Array(  );

  // Create a toolbar movie clip to contain all the tools (including 
  // the color selector) and a nested btns movie clip to specifically // contain the toolbar buttons. _root.createEmptyMovieClip("toolbar", _root.getNewDepth( )); toolbar.createEmptyMovieClip("btns", toolbar.getNewDepth( )); var name, btn; // Create a table for holding the buttons. Set the row spacing to three pixels. t = new Table(3); // Loop through all the names of the buttons. for (var i ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.