Project 6: Creating Interactive Animation
In this chapter's project, you build a basic game in which users can match various shapes by dragging them into their respective holes. Even though building the game is fairly complex, building it demonstrates a handful of very useful techniques. The techniques you learn include creating draggable movie clips, a custom mouse pointer, timers, and even collision detection (detection when two instances on the Stage intersect). To view the final project, go to [www.FLAnimation.com/chapters/06].
Exercise 1: Setting up the project
In this exercise, you create the shapes using Flash's drawing tools. These shapes are the movie clips that you drag around the Stage in the final project. You also add ActionScript to retrieve the X and Y coordinates of each of the shapes that you create.
1. Create a new FLA file. Choose File > Save As and save the document on your hard drive as shapegame.fla.2. Rename Layer 1 on the Timeline as shapes. Draw three shapes on the Stage: a circle, a square, and a triangle by using the Oval (circle), Rectangle (square), and PolyStar tools from the Tools panel (Figure 6.9).
Figure 6.9. Draw three shapes on the Stage. Each shape should be about the same size.
[View full size image]

The easiest way to create a triangle (or any multisided nonrectangular shape) is to click the Rectangle tool in the Tools panel and select the PolyStar tool from the pop-up menu. Click the Options button in the Property inspector to open the Tool Settings dialog box, and specify how many sides you want the polygon to have.

3. Optionally, add some depth to each shape by using the drawing tools. You might use the Line or Brush tools and the Paint Bucket to draw and fill each shape. Or, you can duplicate the existing shape and paste the shape on a lower layer and give the new shape a darker color than the original. When you finish, your shapes might look similar to the following figure.
Figure 6.10. Add some depth to your shapes by using the drawing tools.

Figure 6.11. Select the entire drawing using the Lasso tool.


This code declares a bunch of variables. It is responsible for saving the current X and Y coordinates for the three shapes into variables (such as circleInitX). Flash stores the current X coordinate of circle_mc into a numeric variable named circleInitX. In an upcoming exercise, you use these values to reset the position of the shapes after they've been moved around the Stage.7. Save (File > Save) the changes you made to shapegame.fla.
var circleInitX:Number = circle_mc._x;
var circleInitY:Number = circle_mc._y;
var squareInitX:Number = square_mc._x;
var squareInitY:Number = square_mc._y;
var triangleInitX:Number = triangle_mc._x;
var triangleInitY:Number = triangle_mc._y;
