Recipe 1.1. Drawing Straight Lines


Problem

You want to create a straight line segment or a shape made out of multiple straight line segments.

Solution

Use the Line tool (keyboard shortcut: N), the Pen tool (keyboard shortcut: P), or the Pencil tool (keyboard shortcut: Y) with shift-constraint (explained in detail later in this recipe).

Discussion

Often the simplest way to draw a straight line is to use the Line tool. You can do so by first selecting the Line tool from the Tools panel (Window Tools).With the Line tool selected, drag the mouse on the stage to create a line. Pressing the mouse button creates the starting point, and releasing the mouse button creates the ending point. When using the Line tool, Flash connects the points with a straight line, and applies the active stroke attributes to the line.

You can control the appearance of the stroke, including its color, height, style, end caps, and join types. You can select the Line tool and preset these attributes in the Property inspector before drawing the line on the stage. Alternatively, you can modify an existing line's attributes by selecting the line with the Selection tool and using the Property inspector.

You can create a multisegment line by clicking the mouse close to the end of the previous line segment. Provided the mouse is close enough to an existing segment, Flash automatically joins the line segments into a single path.

Therefore, to create a path comprising a sequence of straight line segments, do the following:

  1. Select the Line tool (N) from the Tools panel.

  2. Press the mouse button on the stage to create a starting point.

  3. Drag the mouse to another location.

  4. Release the mouse button.

  5. Without moving the mouse, click and drag to the next point's location, and then release the mouse button.

  6. Repeat step 5 as necessary.

  7. To close the path, drag the mouse back to the first point in the path before releasing the mouse button.

It is much easier to connect multiple line segments when the View Snap To Objects option is toggled on. For maximum tolerance, under Edit Preferences Drawing, set the Connect Lines option to Can Be Distant. Note that the Connect Lines setting takes effect only when snapping is toggled on. When Flash snaps to an existing line, a large circle beside the cursor indicates the snap. This circle also appears when the line is drawn at an angle in a 90° increment relative to the x and y axes.

To begin a new line, unconnected to an existing line, start the new line far enough away from any existing line so that it doesn't snap to the line. You can append a new segment to an existing line by clicking close enough to one of its end points and dragging to a new location. Likewise, you can create a closed shape by dragging a new line between a line's two end points.

You may want your lines to be constrained to increments of 45° angles relative to the x and y axes. You can force Flash to draw only at these angles by holding down the Shift key as you draw. This technique is called shift-constraint, and it affects most of Flash's drawing tools in one way or another.

Instead of using the Line tool, you can use the Pen tool (P) to draw a straight line or a connected series of line segments. Clicking and releasing on the stage with the Pen tool creates a point. Each subsequent time you click, a new point is added, and Flash draws a line connecting the new point and the preceding point. In that way, the Pen tool is frequently more convenient for drawing a path comprised of line segments, and the Line tool is more convenient for drawing a single line segment. To use the Pen tool to draw a straight line or a series of connected line segments, follow these steps:

  1. Select the Pen tool from the Tools panel.

  2. Click at the starting point and release the mouse button.

  3. Move the mouse (don't drag it) to a new location.

  4. Click again to set the ending point.

  5. Repeat steps 1 to 3 as needed.

To close the path, click again on the first point in the path. To leave a path unclosed, double-click when adding the last point. After closing a shape or double-clicking with the Pen tool, clicking the mouse on the stage again starts a new path.

When you click with the Pen tool, a point is added corresponding to the tip of the Pen tool. If you prefer, you can toggle on a precise cursor with the Pen tool, which replaces the Pen icon with a crosshair. This setting can be found in Edit Preferences Drawing in the Show Precise Cursors checkbox. Another useful preference in the same dialog box is Show Pen Preview, which displays the line that will be created when you click the mouse.

As with the Line tool, you can use shift-constraint to draw lines at 45° increments using the Pen tool. To do so, hold down the Shift key while selecting the points of the line. Flash will automatically snap the end point to the nearest 45° increment relative to the x and y axes.

The Pen tool differs from the Line tool in that it is capable of creating curved lines as well as straight line segments. In addition, Flash highlights points and lines drawn with the Pen tool. Drawing curves and the highlighting are discussed in more detail in Recipe 1.14.

You can also draw straight lines at 90° increments using the Pencil tool (Y) if you use shift-constraint. Using the Pencil tool to draw straight lines can be convenient if you are already using the tool to draw other lines, curves, and shapes, and you don't want to have to change between drawing tools just to draw a straight line. The obvious caveat is that the lines must be at 90° increments relative to the x and y axes.

See Also

Recipe 1.4




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net