AS Reference  :  Notes Index  :  Resources  :  About/Contact  :  Downloads

Using frames and keyframes to create a movie with animation

When you open a new Flash document to begin drawing or importing into, it has one layer and one frame. If you look at the timeline, you'll note that that one frame has a hollow circle in it and the frame has a white background. This indicates that the frame is a keyframe and has no graphic content associated with it on stage. Now draw a shape on stage and you'll see that the frame changes to having a solid black circle with a gray background, which indicates that it is a keyframe which has graphic content associated with it on stage.

Extending the timeline

In order to have animation in a movie (or movieclip, which we'll discuss later), you must extend the timeline to last some specified duration, and put in keyframes wherever you want the scene to change. For example, to create a movie with a blinking star, create a new blank document that's 40 x 40, 12fps, dark blue background. Extend the timeline 12 frames by right-clicking in frame 12 and choosing Insert Frame. Now you have a movie with 12 blank frames (1 second long).

Add Keyframes

Right-click in frame 10 and choose Insert Keyframe to make it a keyframe.

You must insert a keyframe any time you want the content in the timeline to change from its previous state.

Draw a star on stage (hold the mouse down on the Rectangle tool, choose Poly Star tool from the menu that pops up, and in the Properties panel, click Options and choose Star and as many points as you want). Now you should have 9 blank frames, a keyframe in frame 10, and content in frames 10-12 (like the timeline shown below). To see what the movie will look like when published, choose Control, Test Movie (cmd-Enter, pc:ctrl-Enter). The published movie should look like the (somewhat annoying) permanently blinking star below.

First flashing star movie and its timeline

Notice that the movie doesn't just play once and end there -- it goes back to the beginning and plays again. That's an important thing to remember when dealing with any timeline: its default behavior is to start playing and keep playing (looping), unless told to do otherwise. If you want it to play through and stop when it reaches a particular frame, you have to put a stop in that frame (we'll look at that later).

More keyframes can be added to add or refine the animation in a timeline. For example, in the blinking star movie, instead of just two keyframes in 1 and 10, we could add keyframes in frames 11 and 12 (to turn a frame into a keyframe, right-click the frame and choose Insert Keyframe). Then we could use the transform tool or the Transform panel (cmd-T, pc:ctrl-T) to shrink the star in frames 10 and 12, to produce this variation:

Second flashing star movie and its timeline (same overall length, more keyframes for more detail)



Adding keyframe animation to the sheep scene

Now that we've seen how to change the content in a frame by making it a keyframe and then changing the content in that keyframe, let's continue with the sheep scene we created previously and add a keyframe to make the sheep tilt its head and bleat:

And that's it: a movie extended to 32 frames, with one keyframe in the sheep2 head layer (echoed in the sheep2 shadow layer) to tilt it, and one keyframe in the sound layer to add a sound. This creates a 3-second (almost) movie with two seconds of silence, following by one second of bleating, repeating forever (until we learn how to make that stop, as is done in the sample above).

Intro
Flash: What & How
Example Sites
Create
Draw, Edit Shapes
Gradients
More Drawing Tips
Import
A Sample
Animate
Frames, Keyframes
Motion Tweens
More Motion Tweens
Shape Tweens
Masks
Control
Stop/Replay
Movieclips Intro
Movieclip Reference
Site Structure 1
Slideshow Movieclip
Contact Form
Scroll Resume
Preloader
Site Structure 2
Publish
Display Options
Player Detection
Optimize
AS 2.0 Basics
Intro to Syntax
Playhead Commands
Playhead Cmds 2
Coded Tween
onEnterFrame
Intro to Classes
Declare/Assign
Comments, Trace
Simple Data Types
Arrays & Objects
Code Blocks
Operators
Beyond Buttons
Code Structure
Toggle Controls
Group of Buttons
Drag and Hit
Distort Magnifier
Scroll Text
Bee Game
Dart Shooter
Sound Control
Easing Slider
Easing Slider 2
Components Intro
Timers & Delays
Dynamic Content
Intro
Drawing API
Create Text
Attach Movieclips
Easing Slider 3
Easing Slider 4
Load jpg/swf
Sliding Viewer
Preload swf
XML
Easing Slider 5
Server Comm
LoadVars (w/ PHP)
AS - PHP Lookup
Text File
Database 1:LoadVars
Database 2:Remoting
Read from directory
AS 2.0 Classes
Intro
Math
Key
Date
Color
EventDispatcher
New Samples
Pie Chart
Event-model Emailer
Tween Sequence
Fuse Sequence
SVG in Flash
Bitmap Topo
SWF as Data Holder
Two-level Menu
Yahoo! Flash Maps
Class-based Game
ASTB Samples
Disclaimer
3D Outlines
Bounce Collide
Address Book
Save Drawings
Home  :  Notes Index  :  Resources  :  About/Contact  :  Downloads