O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required