Drawing Lines

Think about the steps you take when you draw a line in the real world. You probably have your piece of paper in front of you. You pick up a pen, pencil, or marker. You place the writing instrument down on a specific point on the paper and drag it to another point. If you don't want to continue with another line, you pick up your pen and the job is done. You pretty much follow those same steps when you draw a line using ActionScript. Here's a list of the ActionScript steps:

  • Open a Flash document and the Actions panel. The stage is your paper.

  • Choose a line style. It's similar to choosing a pen, pencil, or whatever.

  • Move to a specific point on the stage. Here's where you put pen to paper.

  • Move to another point, drawing a line in the process, dragging the pen across the paper.

  • Stop drawing lines. Lift the pen from the paper.

Note

The code for the next line-drawing exercise is included in 18-2_Draw_Line.fla in the Missing CD (www.missingmanuals.com/cds).

With those generalizations in mind, here are the specific steps to draw a line on the Flash stage:

  1. Select File→New and choose ActionScript 3.0.

    A new, empty Flash document appears.

  2. Press F9 (Option-F9 on a Mac).

    The Actions window opens, where you can enter ActionScript code.

  3. In the Actions panel, create an instance of the Sprite class by typing the following.

    var sprtLine:Sprite = new Sprite();

    A Sprite is a container like a MovieClip, except it doesn't have a timeline. Using a Sprite instead of a MovieClip when you don't need a timeline ...

Get Flash CS5: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.