Making It Move with Motion Tweens

There are a lot of fun things you can do in Flash, but one that's sure to put a smile on your face is the motion tween. Using the motion tween, it's surprisingly easy to make the objects in your animation move, change shape, change color, or fade to nothingness. The first step is to convert the graphics you want to tween to Flash symbols; then you can change the properties of the symbols at any given point in time—or more specifically, at any point along the timeline. For example, if you have a redwood tree and you want to make it grow, you'd change the height (H) property. For example, in Frame 12, you can set the H property to, say, 100 (pixels), then set it to 150 in Frame 24, 200 in Frame 36, and so on. The tree appears to grow before your audience's eyes. Want to move a car across the stage? Just change the X and Y properties, which set the position on the stage, to create the illusion of movement. (For a rundown on the X/Y coordinate system, see the box on Use X/Y Coordinates to Set Stage Position.)

Chapter 1 showed you how to apply the bounce-smoosh motion preset to a wheel symbol. Motion presets are motion tweens that are predesigned to create certain effects. In the case of bounce-smoosh, it made the wheel drop from the top of the stage to the bottom. When it hit ground, it squashed like a cartoon character and then bounced a couple of times until it came to rest. In the next few exercises, you will create your own version of the bounce-smoosh tween.

Choose View→Rulers to display the handy horizontal and vertical rulers shown here. The rulers mark off the X/Y coordinates of the Flash stage. Want to see the X/Y coordinates for your cursor? Go to Window→Info. The cursor position (circled) shows in the lower-right corner of the Info panel.

Figure 3-10. Choose View→Rulers to display the handy horizontal and vertical rulers shown here. The rulers mark off the X/Y coordinates of the Flash stage. Want to see the X/Y coordinates for your cursor? Go to Window→Info. The cursor position (circled) shows in the lower-right corner of the Info panel.

  1. Open 03-2_Motion_Tween.fla.

    The new document opens, and you see an empty stage.

  2. In the Panels dock, click the Library tab.

    As shown in Figure 3-11, the Library is your warehouse for graphics you want to reuse. There are three items in this Library. For now, focus your attention on the Wheel symbol.

  3. In the Library, click the word "Wheel."

    The wheel appears in the Library's preview window. Notice that images in the Library have different icons next to their names. The gear icon indicates that the wheel is a movie clip symbol. The icon for StairStep shows three different shapes, indicating that it's a graphic icon. You'll learn about the subtle differences between symbols on Symbols and Instances.

  4. Drag the wheel to the top of the stage.

    When you drag a symbol from the Library to the stage, you're creating an instance of the symbol. The original remains safe in the Library, where it can be used again. You can change the size, color, and other properties of your wheel instance without affecting the original.

  5. With the wheel on the stage selected, choose Insert→Motion Tween.

    In the timeline, several frames are added to Layer 1, and the background color for the span changes to blue, the color for a motion tween. The playhead automatically moves to the last frame in the tween.

    Note

    Flash can't tween an image unless it's a symbol (Symbols and Instances). If you try to apply a tween to an object that's not a symbol, Flash asks if you want it converted to a symbol.

  6. Drag the wheel to the bottom of the stage.

    After you drag the wheel to a new position, a dotted line marks the path from the first position to the last (Figure 3-12). This is the motion path, and each dot represents a frame in the animation. A small diamond appears in the last frame of the timeline. The diamond marks the point for a property keyframe, indicating that one of the wheel's properties changed.

  7. Press Enter (Return).

    You see the result of your first motion tween as the wheel moves along the motion path. You can drag the playhead along the timeline to see the position of the wheel at any frame—or in other words, at any point in time. Animators and filmmakers call dragging the playhead manually scrubbing.

For another way to grasp how the motion tween works, examine your symbol's properties. Click the Properties tab and then click the wheel on the stage. In the Properties panel, the Y property (under Position and Size) marks the vertical position of the wheel on the stage. Drag the playhead to a new position, and then select the wheel again. The value of the Y property changes to show the wheel's current position.

The motion tween uses property keyframes, which are similar to standard keyframes except that they track all the individual properties of an object during a tween. For example, property keyframes keep track of the wheel symbol's X and Y coordinates. You animate the symbol by making adjustments to these properties in different frames. It's a two-step process: Move the playhead to mark the point in time, and then change the property. When you change the property, Flash automatically creates a property keyframe in the timeline. In the previous example, Flash automatically moved the playhead when you created the motion tween. You manually changed the Y (position) property when you moved the wheel. In the next example, you'll change the shape of the wheel by adjusting the W (width) and H (height) properties in the Properties panel.

The steps on Making It Move with Motion Tweens showed how to animate the beginning of the bounce-smoosh—the drop. The next step is to add some smoosh. To do so, you need to make the wheel wider and shorter at the moment of impact. To begin, you want to extend the tween and the timeline beyond the bottommost point of the bounce.

  1. Click the frame that's four frames beyond the end frame of the tween.

    The tween ends where the blue highlight ends.

  2. Choose Insert→Timeline→Frame or press F5.

    Frames are added to the end of the animation, and the blue highlight of a motion tween extends to the new end point.

  3. Drag the playhead to the last frame in the tween.

    On the stage, the wheel looks like it did in the previous frame. That won't last long as you begin to fiddle with the properties in the next step.

  4. Click the Properties tab, and then click the wheel on the stage.

    The Properties panel displays the wheel's properties, as shown in Figure 3-13. Note that the H and W properties for the perfectly round wheel are 85 pixels—you'll use this number later.

  5. In the Properties panel, under Position and Size, change the W property to 150. Then change the H property to 60.

    You can change properties by clicking and typing in a new number, or you can click and drag to scrub in a new value.

  6. Press Enter (Return) to test the animation.

    The wheel gradually changes shape from a perfect circle to an oval (Figure 3-14); however, it begins changing shape at the very beginning of the animation. For a proper smoosh, it should change shape on impact with the ground. You can accomplish that with a couple of property tweaks.

  7. Drag the playhead back to the first diamond-shaped property keyframe. Select the wheel and change the W and H properties to 85.

    The wheel returns to its pristine, perfectly round shape.

  8. Press Enter (Return) to test the animation.

    Now, when the animation plays, the wheel retains its roundness until it reaches the bottom of the motion. Then it appears to flatten as it hits the ground.

Flash automatically makes the height and width changes occur smoothly and evenly. Originally, that transition started in Frame 1 and continued through the final frame of the tween. By making the H and W properties identical in Frame 1 and the first property keyframe, the height and width remain the same at the beginning, and the shape change at the end of the animation is faster and more dramatic.

As any school kid can tell you, for every action there's a reaction. Your wheel needs to bounce back from its precarious state. In a word, it needs to de-smoosh. Ideally, you want the next five frames in the animation to be the reverse actions of the last five frames of the tween. You could do that manually, but why reinvent the wheel? (Sorry about the pun.) Instead, you can copy the last five frames, paste them back in at the end of the tween, and then reverse their order. This may sound more complicated than it really is.

Note

The next exercise follows from the steps begun on Making It Move with Motion Tweens. You can use the same Flash document, or download 03-3_Copy_Frames.fla from www.missingmanuals.com/cds.

Here's how to copy and paste frames:

  1. Ctrl-click (⌘-click) the first property keyframe, and then drag to the last frame in the timeline.

    The selected frames at the end of the tween show a dark blue highlight.

  2. Right-click (Control-click) the selected frames, and then choose Copy Frames from the shortcut menu.

    There's no visual response when you copy frames in the timeline, but rest assured that the selected frames are copied and stored so you can paste them in somewhere else on the timeline.

  3. Right-click (Control-click) the first frame after the tween, and then choose Paste Frames from the shortcut menu (Figure 3-16).

    The copied frames are pasted on the end of the timeline. If you press Enter (Return) to preview your animation now, you see that the squashing frames are repeated at the end of the animation.

When you paste the frames on the end of the timeline, Flash creates a second motion tween in Layer 1. You can tell by the solid vertical line followed by a circle keyframe symbol. If you click on frames in either motion tween, you can see the dark blue highlight. The unselected tween has a light blue highlight.

Swapping the order of keyframes in a motion tween lets you do cool things like make a smooshed wheel round again. Simply right-click (Control-click) any frame in the tween and then choose Reverse Keyframes, as shown in Figure 3-17. In the case of your bouncing wheel, the keyframes at the beginning and end of the tween trade places. Preview your animation, and it looks pretty good: The wheel drops down, smooshes, and then recovers its round shape.