Chapter 7. Reusable Flash: Symbols and Templates

The secret to productivity is to work smarter, not harder. And the secret to smart work is to avoid doing the same thing more than once. Flash understands. The program gives you ways to reuse bits and pieces of your animations—everything from simple shapes to complex drawings, multiframe sequences, and even entire animations. Create something once; reuse it as many times as you like. Reusing animation elements can save you more than just time and effort—Flash lets you store pieces of animation as reusable master copies that can actually whittle the size of your finished animation file. That's great news if you plan to put your animation up on a website or shoot it out to handhelds. The smaller your file size, the faster it downloads, which makes you less likely to lose your audience to impatience.

Templates are another work- and time-saving feature in your Flash arsenal. You can use these predesigned Flash documents as starting points for your own projects. Even better, you can save documents as templates. You can also save templates containing the pictures, logos, and other elements that appear in just about all your documents. Then you don't have to start from scratch next month when you have a similar project.

Tip

With Flash Professional CS5, Adobe has included several new templates that serve as hands-on learning tools. Want to learn how to create random movement? Check out the templates in the Animation category. You'll find several button examples, as well as techniques for creating rain and snow effects. In the Sample Files category, some of the examples include handwriting simulations, menu navigation tools, and walking figures.

Copying and pasting is the most obvious way to reuse something you've created, but while that time-honored technique saves time, it doesn't save space. Say, for example, you need to show a swarm of cockroaches in the Flash advertisement you're creating for New and Improved Roach-B-Gone. You draw a single cockroach, then copy and paste it 100 times. Congratulations: You've got yourself 100 cockroaches…and one massive Flash document.

Instead, you should take that first cockroach and save it in Flash as a symbol. Symbols give you a way to reuse your work and keep your animation's finished file size down to a bare minimum. When you create a symbol, Flash stores the information for the symbol, or master copy, in your document as usual. But every time you create a copy (an instance) of that symbol, all Flash adds to your file is the information it needs to keep track of where you positioned that particular instance and any modifications you make to it on the stage.

So, to create the illusion of a swarm of roaches, you drag instances of the symbol onto the stage. Neither you nor Flash have to duplicate the work of drawing each roach. You can even vary the roach instances a little for variety and realism (so important in a pesticide ad) by changing their color, position, size, and even their skew. If symbols offered only file optimization, they'd be well worth using. But symbols give you additional benefits:

Flash lets you create three types of symbols: graphic symbols, movie clip symbols, and button symbols. As you see in Figure 7-1 Flash stores all three types of symbols in the Library.

You can tell Flash to turn everything from a simple shape (like a circle or a line) to a complex drawing (like a butterfly) into a symbol. You can also nest graphic symbols. For example, you can nest butterfly wing symbols inside a butterfly symbol, as shown Figure 7-2.

A graphic symbol isn't even limited to a static drawing. You can save a series of frames as a multiframe graphic symbol that you can add to other animations.

Flash gives you two options for creating a graphic symbol:

If you've already got an image on the stage that you'd like to turn into a symbol, you're in luck: The process is quick and painless.

To convert an existing image on the stage to a graphic symbol:

  1. On the stage, select the image (or images) you want to convert.

    Flash's selection tools are described on Selecting Objects on the Stage. Converting a grouped or editable image into a graphic symbol is quick and easy. Figure 7-3 shows three separate images selected that, all together, form a star.

  2. Select Modify→Convert to Symbol.

    The Convert to Symbol dialog box appears.

  3. In the Name text box, type a name for your symbol.

    Because you'll be creating a bunch of instances of this copy over the course of the next several hours, days, or weeks (and because you may end up with dozens of symbols before you're finished with your animation), you want a unique, short, descriptive name.

  4. Set the Type drop-down menu next to Graphic, and then click OK.

    Flash creates the new graphic symbol, places it into the Library, and automatically replaces the selected image on the stage with a selected instance of the symbol (Figure 7-4). Notice the instance's single bounding box (the original three images in this example had three).

    Tip

    If you're already poking around the Library panel, you can create a new graphic symbol quickly by clicking the Library panel's New Symbol button (Figure 7-1) or by clicking the Library panel's Options menu, and then, from the pop-up menu that appears, selecting New Symbol. Either way tells Flash to display the Create New Symbol dialog box.

If you want to create a symbol from scratch without going through the conversion step described above, you can use Flash's symbol editor—the same symbol editor you use to modify your symbols.

To create a graphic symbol in symbol editing mode:

  1. Select Insert→New Symbol.

    The Create New Symbol dialog box shown in Figure 7-5 (top) appears.

  2. In the Name text box, type a name for your symbol.

    Shoot for unique, short, and descriptive.

  3. From the drop-down menu, choose Graphic, and then click OK.

    Flash displays the symbol editing workspace shown in Figure 7-5 (bottom). The symbol editing workspace looks very much like an animation workspace, even down to the background color. Here are the key differences that indicate you're in symbol editing mode:

  4. On the symbol editing workspace, create a graphic symbol.

    You can use Flash's drawing tools, instances of other symbols, or even an imported image (Chapter 10), just as you can on the main stage. As you draw, Flash displays a thumbnail version of your symbol in the Library preview window, as shown in Figure 7-7. Note that the use count is zero, until you drag an instance of the symbol onto the stage. The use count is the number of instances of this symbol that have been dragged onto the main animation stage.

  5. When you're finished creating your symbol, head to the Edit bar, and then click the Back arrow or click the current scene icon. (Or use the menu command Edit→Edit Document.)

    Flash brings you back to your main animation workspace.

After you've created a symbol, you use it by creating an instance of that symbol and then placing the instance somewhere in your animation.

Follow these steps to add an instance of a graphic symbol to your animation:

The whole point of graphic symbols is to help you reuse images (and to help Flash keep down file size while you're doing it). So it should come as no surprise that you can't completely rework the instances you create. You can't, for example, create an instance of a ladybug, erase it, draw a toad in its place, and expect Flash to consider that toad an instance of the ladybug symbol.

But while you can't use Flash's drawing and painting tools to change your instance, you can change certain characteristics of an instance, including color, transparency, tint, and brightness using the Properties panel; and scale, rotation, and skew using the Transform panel.

You can also edit an instance by swapping one instance of a graphic symbol for another. Say, for example, that you've created a nature backdrop using multiple instances of three symbols: a tree, a bush, and a flower. If you decide you'd rather replace a few trees with bushes, Flash gives you a quick and easy way to do that, as shown in the following steps:

  1. On the stage, select the instance you want to replace.

    Flash displays the Properties panel to show instance-related properties. (If you don't see the Properties panel, choose Window→Properties to display it.)

  2. In the Properties panel, click Swap (Figure 7-9).

    The Swap Symbol dialog box appears.

  3. In the Swap Symbol dialog box, click to select the symbol with which you'd like to replace the original. When you finish, click OK.

    On the stage, Flash replaces the selected instance with an instance of the symbol you chose in the Swap Symbol dialog box.

Recoloring or transforming an instance changes only that instance, but editing a symbol changes every single instance of that symbol, immediately, wherever you've placed them in your animation.

The good news about editing symbols, of course, is that it can save you a boatload of time. Say you've added hundreds of instances of your company's logo to your animation and the brass decides to redo the logo. Instead of the mind-numbing chore of slogging through your animation finding and changing each instance by hand, all you have to do is edit one little image—your logo symbol. The minute you do, Flash automatically ripples your changes out to each and every instance of that symbol.

The bad news, of course, is that you might edit a symbol by mistake, thinking you're editing an instance (Editing an instance of a graphic symbol). Editing a symbol is for keeps. You can select Edit→Undo if you realize your mistake in time, but once you close your Flash document and Flash erases your Undo history, it's all over but the crying: You're stuck with your edited symbol, for better or for worse.

Flash gives you three ways to edit symbols: Edit, Edit in Place, and Edit in New Window.

In a nutshell, to tell Flash you want to edit a symbol, do any of the following.

In the Library panel:

On the stage:

No matter which method you choose—editing, editing in place, or editing in a new window—you get out of symbol editing mode and return to the main stage the same way: by selecting Edit→Edit Document (Ctrl+E on a PC or ⌘-E on a Mac).

Multiframe graphic symbols are a kind of hybrid symbol halfway between single frame graphic symbols and movie clip symbols. Multiframe graphic symbols can't contain sounds or actions the way movie clip symbols can, but they can contain multiple frames, which regular single-frame graphic symbols can't. As explained in the box on Multiframe Graphic Symbol vs. Movie Clip, multiframe graphic symbols synchronize frame-for-frame to the animation in which you place them.

Flash gives you the same two options for creating multiframe graphics symbols as it does for single-frame graphic symbols: You can create a series of frames as usual and then convert it into a reusable symbol, or you can use Flash's editing mode to create a multiframe graphic symbol from scratch and save yourself the conversion step. This section shows both approaches.

To convert a series of frames to a multiframe graphic symbol:

  1. On the timeline, select the frames you want to convert.

    You can easily select a series by clicking at one end of the series and then Shift-clicking at the other end. Flash automatically selects all the frames in between.

  2. Choose Edit→Timeline→Copy Frames or press Ctrl+Alt+C (Option-⌘-C). Then choose Insert→New Symbol.

    The Create New Symbol dialog box appears.

  3. In the Create New Symbol dialog box, turn on the Graphic radio button. Type a short, descriptive name for your symbol, and then click OK.

    The name of your symbol appears in the Library panel and in the Edit bar above your stage to let you know you're in symbol editing mode. In addition, Flash replaces your animation stage with the symbol editing stage. You can recognize the symbol editing stage by the cross (your symbol's registration point) that appears in the middle of the symbol editing stage.

  4. In the symbol timeline, click to select the first keyframe (Frame 1).

    Flash highlights the selected keyframe.

  5. Select Edit→Timeline→Paste Frames.

    Flash pastes the copied frames in the symbol's timeline. The Library panel's preview window shows you the contents of your new symbol's first keyframe (along with a minicontroller, as shown in Figure 7-13).

  6. Preview your symbol by clicking the minicontroller's Play button.

    Flash runs a thumbnail version of the symbol in the preview window.

  7. Get out of symbol editing mode by choosing Edit→Edit Document.

Flash hides the symbol editing stage and brings you back to your main animation's stage and timeline. To create a multiframe graphic symbol from scratch in symbol editing mode, follow the steps you see on Creating a graphic symbol in symbol editing mode, adding the content for as many frames as you need in step 5.

Creating an instance of a multiframe graphic symbol is like creating an instance of a movie clip symbol, but it's not identical. When you insert a multiframe graphic symbol into a timeline, the graphic synchronizes frame-for-frame with that timeline. If the timeline doesn't have enough frames, Flash lops off any frames of the graphic that don't fit. If the timeline has more frames than the graphic, Flash loops the graphic frames unless you provide other instructions in the Properties panel. If it's important that every frame of the graphic plays, make sure the timeline has enough frames. The following steps show you how.

To create an instance of a multiframe graphic symbol:

  1. In your main animation, click to select the keyframe where you want to place an instance of a multiframe graphic symbol.

    Only keyframes can contain new content (see Creating a Frame-by-Frame Animation for the skinny on keyframes). So if you try to place a symbol in a regular frame, Flash "backs up" and places your symbol in the keyframe immediately preceding the selected frame anyway.

  2. Make sure you have exactly as many frames after the selected keyframe as you need for this instance.

    If you're creating an instance of a symbol that contains 10 frames, make sure 10 frames exist, including the selected keyframe. If the symbol contains 20 frames, make sure 20 frames exist. To add frames after your selected keyframe, choose Insert→Timeline→Frame (or press F5) once for each frame you want to add.

  3. In the Library, click to select the multiframe graphic symbol of which you want to create an instance.

    You can either click the symbol's icon from the list or click the symbol's thumbnail in the preview window. The Library lists the type of both single and multiframe graphics the same—Graphic—but you can always tell a multiframe graphic by the minicontroller that appears along with the symbol's content in the Library's preview window, as shown in Figure 7-13.

  4. Drag the symbol to the stage.

    Flash creates an instance of the symbol and places it in the keyframe you selected in step 1. As you see in Figure 7-14, Flash colors your frames a nice solid gray to let you know that they now contain content. But Flash doesn't display the individual keyframes of your instance in your main timeline. (By the same token, if your symbol contains multiple layers, you don't see those on your main timeline, either. This visual simplification is one of the benefits of using symbols, as opposed to just copying and pasting frames.) To preview your instance, select Control→Test Movie→Test.

If you need the flexibility to individually change each keyframe of a multiframe graphic instance, you're out of luck, but you can use the Transform tool and the Properties panel to make tweaks that affect every frame of your multiframe graphics. Use the Properties panel to change the size, position, and color of your graphic, as shown in Figure 7-15. Changes you make here affect every frame in the multiframe graphic.

Flash lets you change the contents of the first keyframe of your instance, just the way you can an instance of a single-frame graphic (Editing an instance of a graphic symbol). But Flash automatically applies those changes to the contents of every keyframe in your instance. Skew the frog in your first keyframe and turn it blue, for example, and every image in every frame of your instance appears skewed and blue.

Using the Properties panel, you can tweak the playback settings for a multiframe graphic. Under Looping→Options you can choose between Loop, Play Once, and Single Frame. In the First box, you can choose the first frame that Flash displays. For example, suppose you have a nifty countdown multiframe graphic like the ones at the beginning of old newsreels. Your graphic counts down from 10, but for this project you'd like to start it at 8, like in the movies. Simply adjust the starting frame so that it begins when the 8 is showing, as shown in Figure 7-15.

A movie clip symbol (Figure 7-16) is a reusable, self-contained chunk of animation, which you can drop into a single frame in another animation.

Unlike multiframe graphic symbols, you can add sounds (Chapter 11) and actions (Chapter 12) to movie clip symbols. Also unlike multiframe graphic symbols, movie clip symbols run independently from the animations to which you add them.

So movie clips give you the opportunity to create nonsequential effects like repeating, or looping, scenes, as well as interactive graphics—for example, buttons, checkboxes, and clickable images that tell Flash to display something different, depending on what your audience clicks.

As you'll see in the following section, movie clip symbols have their very own timelines, so an instance of a movie clip symbol always takes up just one frame in the animation to which you add it, no matter how many frames the movie clip symbol actually contains.

Creating a movie clip symbol in Flash is similar to creating a multiframe graphic symbol (Multiframe Graphic Symbols). You can either create a series of frames (including sounds and actions, if you like) and convert it into a movie clip symbol, or you can use Flash's editing mode to create a movie clip symbol from scratch and save yourself the conversion step.

In fact, as the following steps show, only one minor but important difference exists between creating a multiframe graphic symbol and creating a movie clip symbol, and that's selecting the correct drop-down menu option in step 4.

To convert a series of existing frames to a movie clip symbol:

  1. On the timeline, select the frames you want to convert.

    It's easy to select a series of frames. Click at one end of the series, and then Shift-click at the other end of the series. Flash automatically selects all the frames in between. If your frames contain layers, make sure you select all the layers in each frame.

  2. Choose Edit→Timeline→Copy Frames or press Ctrl+Alt+C (Option-⌘-C).

    Flash copies the frames.

  3. Choose Insert→New Symbol.

    The Create New Symbol dialog box appears.

  4. In the Create New Symbol dialog box, make sure to choose Movie Clip from the drop-down menu.

    If it's not selected, click to select it.

  5. Type a name for your movie clip symbol, and then click OK.

    The name of your movie clip symbol appears in the Library panel, and in the Edit bar above your stage, to let you know you're in symbol editing mode. Another tip-off that you're in symbol editing mode is the cross, or registration point, that appears in the middle of the symbol editing stage.

  6. In the symbol timeline, click to select the first keyframe (Frame 1).

    Flash highlights the selected keyframe.

  7. Select Edit→Timeline→Paste Frames.

    Flash pastes the copied frames onto the symbol's timeline and displays the first keyframe of the new symbol (along with a minicontroller) in the Library panel's preview window.

  8. In the Library panel, preview your symbol by clicking the minicontroller's Play button.

    Flash runs a thumbnail version of the movie clip symbol in the preview window.

  9. Get out of symbol editing mode by choosing Edit→Edit Document.

    Flash brings you back to the workspace and your main animation.

To create a movie clip symbol from scratch in symbol editing mode, follow the steps on Creating a graphic symbol in symbol editing mode, adding the content for as many frames as you need.

Because movie clip symbols have their own timelines, they're completely self-contained. You don't have to worry about matching your movie clip symbol to your main animation's timeline the way you do with a multiframe graphic symbol (Multiframe Graphic Symbols); movie clip instances live on a single frame in your main animation, no matter how many frames the instances themselves contain. As a matter of fact, as you'll see next, creating an instance of a movie clip symbol is as easy as dragging and dropping.

To create an instance of a movie clip symbol:

You'll notice that even if you turn looping off in the Control panel (which you do by selecting Control, and then, from the pop-up menu that appears, turning off the checkbox next to Loop) your movie clip instance continues to loop. The movie clip behaves this way because it's running on its own timeline (not the timeline Flash associates with your main animation). One way to tell Flash to stop looping your movie clip instance is to add a keyframe to your timeline after the keyframe that contains your movie clip instance. It can be a blank keyframe or a keyframe with content other than the movie clip you intend to stop.

Similar to multiframe graphic symbols, Flash lets you change the contents of the first keyframe of your movie clip instance, just the way you can an instance of a single-frame graphic (Editing a graphic symbol). But Flash automatically applies those changes to the contents of every frame in your instance. So, for example, if you apply a sepia tint to the first keyframe, your entire movie clip instance looks old-timey. You can also apply filters (Editing an instance of a button symbol) and blending effects to movie clip instances.

The easiest way to make your animation interactive is to add a button someone can click at runtime to perform a task, like replaying your entire animation, choosing which of several scenes to play, loading a web page, and so on.

To make creating a button easy, Flash has button symbols (Figure 7-19). A button symbol has four frames. Each frame has a specific function that helps you control the appearance of the button as it's being used by your audience:

For the designer, button symbols are handy. Flash automatically gives you the four Up, Over, Down, and Hit frames—all you have to do is plug in your drawings and go. As you'll see in the following section, Flash also gives you a handful of built-in graphic effects, called filters, which you can apply to your buttons to get professional-looking results. Button symbols aren't the only way to provide clickable interactivity to your projects. ActionScript coders often create their own buttons or use button components (Adding Components).

When you create a button symbol, you start out basically as if you're creating any graphic symbol from scratch (Creating a graphic symbol in symbol editing mode), but since button symbols have those four possible states, you can create up to four different graphics. When you choose Button in the New Symbol dialog box, Flash gives you a separate frame to hold each drawing so that you won't get confused.

In this example, you'll create a round, red button that turns yellow when your audience mouses over it and green when your audience clicks it.

  1. Click Insert→New Symbol.

    The Create New Symbol dialog box appears.

  2. In the Name text box, type bullseye. Make sure the drop-down menu is set to Button, and then click OK.

    When you create a new button symbol, Flash gives you four named frames (Figure 7-20). It's up to you which frames you want to modify, but at the very least, you need to add a drawing to the Up frame, to show the button before it's clicked or moused over. For a more sophisticated button, you'll also add a drawing to the Over frame (as shown below) to let someone know when his mouse is over the button.

  3. Draw your button as you want it to appear initially by using the Oval tool to add a red circle to the first keyframe (the Up frame).

    Keep the registration point (the cross) in the upper-left corner of your button image as you draw. When you finish, your workspace should look similar to the one in Figure 7-21.

  4. Right-click Frame 2 (the Over frame), and then, from the pop-up menu that appears, select Insert Keyframe.

    Flash displays a circle in Frame 2 to let you know you've successfully added a keyframe. On the stage, you see a copy of the button you drew in Frame 1.

  5. Here's how you make the button change when a cursor passes over it: On the stage, select the circle. In the Properties panel, click the Fill Color icon, and then, from the color picker that appears, choose a yellow swatch.

    Flash recolors the circle yellow. If you don't see the Properties panel, select Window→Properties. If you still don't see it, make sure you've selected the circle on the stage.

  6. Right-click Frame 3 (the Down frame), and then, from the pop-up menu that appears, select Insert Keyframe.

    Flash displays a circle in Frame 3 to let you know you've successfully added a keyframe (and, therefore, can change the content of the frame).

  7. Here's how you draw the button as you want it to appear when a cursor clicks it: Select the button. In the Properties panel, click the Fill Color icon once again, and then, from the color picker that appears, choose a green swatch.

    Flash recolors the circle green.

  8. Right-click Frame 4 (the Hit frame), and then, from the pop-up menu that appears, select Insert Keyframe.

    Flash displays a circle in Frame 4 to let you know you've successfully added another keyframe. As you can see on the stage, Flash assumes you want the entire button to respond to a mouse click—and in a lot of cases, that's exactly what you do want. But you can make the clickable portion of your button smaller or larger. To do so:

  9. On the stage, click the circle to select it. Then choose Window→Transform to display the Transform panel.

    In the Transform panel, type 50 into the Width and Height boxes, and then press Enter or Return. Figure 7-22 shows you a scaled-down circle that should look similar to the one you see on your workspace.

  10. Return to your animation by choosing Edit→Edit Document.

    Flash hides your symbol editing workspace and displays your animation workspace.

You can find the work file from the previous exercise 07-3_Bullseye_Button at www.missingmanuals.com/cds.

To create an instance of a button symbol:

Note

Chapter 13 shows you how to add an action to your button so that clicking it does something useful.

You can't change the individual frames of your button instance individually. But Flash does let you apply the same changes to all the frames of your button instance. Creating a button symbol shows you the steps you can take to apply color, transparency, and transforms to your button instances. (The steps are identical to those you take to edit a single-frame graphic instance.) But you can also apply filters, or visual effects, to your buttons. Filters can turn even a plain oval button into something that looks like you spent hours tweaking it.

To apply a filter to a button instance:

  1. On the stage, select the button instance.

    Flash draws a blue selection box around the instance.

  2. In the Properties panel, click the Filters subpanel.

    If the Filters subpanel is closed, click the triangular button to expand it.

  3. Click the Add Filter button (lower-left corner).

    A pop-up menu appears (Figure 7-25) listing the following filter options:

    • Drop Shadow. Displays a shadow on the right and bottom edges of the button.

    • Blur. Redraws the surface of the button so that it appears soft and blurred.

    • Glow. Similar to a drop shadow, creates a fuzzy aura in the color of your choosing.

    • Bevel. Applies brightness and shadow on opposite sides of the button to create a 3-D effect.

    • Gradient Glow. Similar to Glow (above), but lets you specify bands of different colors (instead of just one color).

    • Gradient Bevel. Similar to Bevel (above), but lets you choose bands of different colors for the brightness and shadow.

    • Adjust Color. Lets you individually adjust the brightness, contrast, saturation, and hue of your button.

  4. From the menu, select Glow.

    A red, glowing effect appears around your button, and the Filter panel displays the Glow properties.

  5. Click the down arrow next to Blur X, and then drag the slider to 40.

    On the stage, the glow diffuses.

  6. Click the Shadow Color icon, and then, from the color picker that appears, click the black swatch.

    On the stage, the glow turns from red to black, yielding a subtle 3-D effect (Figure 7-26).

  7. Test your newly edited button by selecting Control→Test Movie→Test.

    In the test window that appears, you see your button with the Glow effect applied.

  8. In the test window, move your mouse over your button.

    Flash applies filters to the entire instance (not just the contents of the keyframe to which you apply them), so the Glow effect remains even when you mouse over the button.

To remove a filter you've applied: In the Filter panel, select the filter you want to remove, and then click the Delete Filter button (trash can).

You edit a multiframe graphic symbol, like a button, the same way you edit a single-frame graphic symbol: by switching to symbol editing mode (Editing a graphic symbol). In both cases, Flash immediately applies the changes you make to the button symbol itself, as well as all the instances of that button symbol.