Flash Basic 8 and Flash Professional 8 offer several ways to include animation and special effects in your document. For example, you can create tweened animations using the Timeline and Flash workspace, automated Timeline effects (by making selections in a dialog box), or ActionScript code.
To create tweened animations, you create starting and ending frames and let Flash create the animation for the frames in between. Flash varies the object's size, rotation, color, or other attributes between the starting and ending keyframes to create the appearance of movement. You can also create animation by changing the contents of successive frames in the Timeline. You can make an object move across the Stage, increase or decrease its size, change its color or shape, rotate it, and even fade in or out. Changes can occur independently of, or in concert with, other changes. For example, you can make an object rotate and fade in as it moves across the Stage. In frame-by-frame animation, you create the image in every frame.
You have several options when creating tweened animations. You can create traditional frame-by-frame animations (see the section, Creating Frame-by-Frame Animations, http://macromedia.com/devnet/flash/articles/animation_guide_09.html), motion tweens (see Creating Motion Tweens, http://macromedia.com/devnet/flash/articles/animation_guide_05.html), or shape tweens (see Creating Shape Tweens, http://macromedia.com/devnet/flash/articles/animation_guide_07.html).
Timeline effects include animated vector effects such as blur, expand, and explode. This feature makes it easy to animate an object: you can simply select the object and then select an effect and specify its parameters. With Timeline effects, you can accomplish in a few easy steps a previously time-consuming task that required more advanced knowledge of animation.
You can also create an animation by writing ActionScript code, which is sometimes called scripted animation. There are different ways you can script animation: you can write ActionScript to handle all aspects of the animation or you can use prebuilt classes and simpler code to create an animation. Using prebuilt classes makes animating with code quite easy.
Using code to create animations and effects often reduces the file size of your finished application, and can also improve the performance and consistency of the animation itself. At times, ActionScript-based animations might even reduce your workload: code can be faster to write, and it's easy to apply to many instances at once or reuse in other applications. The following sections introduce you to scripted animation fundamentals, animation using the Tween and TransitionManager classes, and integrating animation with both the Drawing API and filter classes.
Note: For more information on filter effects, see the Flash Graphic Effects Learning Guide (http://macromedia.com/devnet/flash/articles/graphic_effects_guide.html).
Requirements
To make this most of this tutorial, you need to install the following software and files: Macromedia Flash Basic 8 or Macromedia Flash Professional 8
Prerequisite Knowledge
A basic knowledge of the Flash user interface.
About Frame Rate and Animation
The frame rate, the speed at which an animation is played, is measured in number of frames per second. A frame rate that's too slow causes the animation to appear jerky; a frame rate that's too fast might negatively affect the animation or use too much of the user's computer processing power. The complexity of the animation and the speed of the computer on which the animation is being played affect the smoothness of the playback. Test your animations on a variety of machines to determine optimum frame rates.
You need to think about frame rate when working with animations because it can affect the performance of your SWF file and the computer that plays it. Setting a frame rate too high can lead to processor problems, especially when you use many assets or use ActionScript to create your animation. However, you also need to consider the frame rate setting because it affects how smoothly your animation plays.
For example, an animation set to 12 frames per second (fps) in the Property inspector plays 12 frames each second. If the document's frame rate is set to 24 fps, the animation appears to animate more smoothly than if it ran at 12 fps. However, your animation at 24 fps also plays much faster than it does at 12 fps, so the total duration (in seconds) is shorter. Therefore, if you need to make a five-second animation using a higher frame rate, it means you need to insert additional frames to fill those five seconds than at a lower frame rate‹which raises the total file size of your animation. A five-second animation at 24 fps typically has a higher file size than a five-second animation at 12 fps, depending on your assets and how you are animating the content.
Tip: Because you specify only one frame rate for the entire Flash document, it's a good idea to set this rate before you begin creating the animation.
Note: When you use an onEnterFrame event handler to create scripted animations, the animation runs at the document's frame rate, as if you created a motion tween on a timeline. An alternative to the onEnterFrame event handler is setInterval. Instead of depending on the frame rate, you call functions at a specified interval. Like onEnterFrame, the more frequently you use setInterval to call a function, the more resource-intensive the animation is on your processor.
Use the lowest possible frame rate that makes your animation appear to play smoothly at runtime because it will help reduce the strain on the end-user's processor. Try not to use a frame rate that's more than 3040 fps; high frame rates put a lot of stress on processors. Also, do not change the appearance of the animation much, or at all, at runtime.
Finally, especially if you're working with Timeline-based animations, select a frame rate for your animation as early as possible in the development process. When you test the SWF file, check the duration and the SWF file size of your animation. The frame rate greatly affects the speed of the animation.
Creating Keyframes for Animations
A keyframe is a frame in which you define changes in the animation. When you create a frame-by-frame animation, most frames are keyframes. In a tweened animation, you define keyframes at significant points in the animation and let Flash create the contents of the frames in between. Flash displays the interpolated frames of a tweened animation as light blue or light green and with an arrow drawn between keyframes. Because Flash documents save the shapes in each keyframe, you should create keyframes only at those points in the artwork where something changes.
Keyframes are indicated in the Timeline: A keyframe with content on it is represented by a solid circle; an empty keyframe is represented by an empty circle within the frame. Subsequent frames that you add to the same layer have the same content as the keyframe.
To create a keyframe, do one of the following:
Motion tweens are indicated by a black dot at the beginning keyframe; intermediate tweened frames have a black arrow with a light blue background.
Shape tweens are indicated by a black dot at the beginning keyframe; intermediate frames have a black arrow with a light green background.
A dashed line indicates that the tween is broken or incomplete, such as when the final keyframe is missing.
A single keyframe is indicated by a black dot. Light gray frames after a single keyframe contain the same content with no changes and show a black line with a hollow rectangle at the last frame of the span.
A small a indicates that the frame has frame scripts assigned to it with the Actions panel.
A series of keyframes with a light gray background might indicate a frame-by-frame animation.
A hollow circle represents a blank keyframe, and white frames represent frames with no content. This frame begins a section with no content on the layer. For example, if you have an instance that blinks on a layer, you might insert blank keyframes where you do not want the instance to appear.
Creating Tweened Animations
Flash can create two types of tweened animation: motion tweening and shape tweening.
In motion tweening, you define properties such as position, size, and rotation for an instance, group, or text block at one point in time, and then change those properties at another point in time. After you do so, you can apply the motion tween between those two frames. Flash automatically creates the movement between the first and second point in time. You can also apply a motion tween and assign a path for it to follow. For more information on motion tweens, see the next section, Creating Motion Tweens.
In shape tweening, you draw a shape at one point in time, and then change that shape or draw another shape at another point in time. Flash interpolates the values or shapes for the frames in between, thus creating the animation. The shape morphs from the first shape into the second shape. For more information on shape tweens, see the later section, Creating Shape Tweens.
Note: To apply shape tweening to groups, instances, or bitmap images, you must first break these elements apart (Modify > Break Apart). To apply shape tweening to text, you must break the text apart twice to convert the text to objects.
Tweened animation is an effective way to create movement and changes over time while minimizing file size and development time. In tweened animation, Flash stores only the values for the changes between frames. To quickly prepare elements in a document for tweened animation, distribute objects to layers (Modify > Timeline > Distribute to Layers).
Creating Motion Tweens
To tween the changes in properties of instances, groups, and type, you use motion tweening. Flash can tween position, size, rotation, and skew of instances, groups, and type. Additionally, Flash can tween the color of instances and type, creating gradual color shifts or making an instance fade in or out. To tween the color of groups or type, you must make them into symbols.
If you apply a motion tween and then change the number of frames between the two keyframes, or move the group or symbol in either keyframe, Flash automatically tweens the frames again.
You can create a motion tween using one of two methods:
When tweening a position, you can make the object move along a nonlinear path. To create a motion tween using the Motion Tweening option:
To produce a more realistic sense of motion, you can apply easing to the motion tween you create. Flash provides two methods by which you can apply easing to a motion tween: You can specify an easing value for each motion tween you create using the Ease slider, or you can use the Custom Ease In/Ease Out dialog box (Flash Professional only) to control the speed of the motion tween more precisely.
To apply regular easing to a motion tween:
The Custom Ease In/Ease Out dialog box displays a graph representing the degree of motion over time. Frames are represented by the horizontal axis and the tween's percentage of change is represented by the vertical axis. The first keyframe is in the animation is at 0% and the last keyframe is at 100%. The rate of change of the tweened instance is shown by the slope of the graph's curve. If you create a horizontal line (no slope) on the graph, the velocity is zero; if you create a vertical line on the graph, there is an instantaneous rate of change.
To open the custom easing dialog box:
Using frame indicators (represented by square handles), you click where you want an object to slow down or speed up. Clicking the handle of a control point (the square handles) selects that control point and displays the tangent points on either side of it. Tangent points are represented by hollow circles. You can drag the control point or its tangent points with the mouse or you can position them using the keyboard's arrow keys.
Tip: By default, the control points snap to a grid. You can turn off snapping by pressing the X key while dragging the control point.
Clicking an area of the curve away from any control points adds a new control point to the curve at that point without changing the shape of the curve. Clicking away from the curve and control points deselects the control point that is currently selected.
Part 2 is in the next issue (MXDJ 3-12)