Templates

While symbols let you reuse images and series of frames, templates let you reuse entire Flash documents. In this section, you see how to use Flash's prebuilt templates and how to create your own. In Flash CS5, templates are helpful in several ways:

Flash CS5 comes with a bunch of templates all ready for you to customize. You see them on the welcome screen (Figure 7-28) when you start Flash (or choose File→New and then click the Templates tab). While they're obviously not specific to your particular company or project, they can save you time on a lot of basic animations, including banner ads, slideshows, and presentations. They're also great examples for learning new Flash skills. Here's a quick rundown of the major template categories.

When you first start Flash, the major template categories are displayed on the welcome screen. If you don't see the welcome screen when you start Flash, you can always open a template using the File→New command and then clicking the Templates tab.

Figure 7-28. When you first start Flash, the major template categories are displayed on the welcome screen. If you don't see the welcome screen when you start Flash, you can always open a template using the File→New command and then clicking the Templates tab.

Templates in the Sample File group can help you master specific tools and techniques. The IK Stick Man Sample shown here shows how to use Flash's Bone tool (page 318).

Figure 7-29. Templates in the Sample File group can help you master specific tools and techniques. The IK Stick Man Sample shown here shows how to use Flash's Bone tool (page 318).

Note

Flash's templates are useful—if you can figure out what they're supposed to do and how to customize them. You're at the mercy of the people who created the templates. If you're lucky, they provided a helpful name and description that appears in the dialog box where you choose a template. If you're very, very lucky, they provided instructions, comments, and notes in the template itself.

Starting a document from a template is similar to opening an existing document. There's one big difference, though. When you use a template to create a new document, the original template remains untouched. It's as if you opened an existing document and immediately used Save As to save it under a new name. Here are the steps to use one of the prebuilt templates that come with Flash:

  1. Select File→New.

    The New Document window appears.

  2. In the New Document window, click the Templates tab.

    The New from Template window opens (Figure 7-30).

  3. In the Category box, select Animation.

    Several animation templates appear selected in the Templates box.

  4. At the top of the list, click Animated Button Highlight.

    The Preview window shows the stage for the selected template. Sometimes you won't see anything but the shape of the stage. For the Animated Button Highlight, you see the button. The description gives you some hints about the template and what it is designed to do.

  5. Click OK.

    Flash opens the template, and you're ready to roll. Several of the prebuilt templates have instructions, and so does this one. They're in the top layer of text on the stage. After you've read the instructions, you can delete or hide the layer. These instructions explain how to change the button's appearance and behavior.

With many templates, the best way to start is with a test drive. Watch the animation, then examine its timeline, symbols, and any ActionScript code that makes it work. In the Animated Button Highlight template, press Ctrl+Enter (⌘-Return) to see how the animation works in the Flash Player test window. It's pretty basic: There's one big button on the center of the stage labeled "click." When you mouse over the button, its appearance subtly changes—it starts to blink. Click the button, and its appearance changes again—it stops blinking and has a pressed-down appearance. The Output panel down near the timeline reads, "Button clicked."

Close the Flash Player window and go back to the stage. Click the Timeline tab, and you can start to explore the mysteries of this template. For example, select the button on the stage, and then check out the Properties. You see the button is a movie clip symbol rather than a button symbol. Double-click the button on the stage, and it opens so you can see the timeline for the symbol, as shown in Figure 7-31. This particular template uses some Flash tools that you'll learn about later in this book: ActionScript (Customizing the Video Playback Component) and timeline labels (Working with Labeled Frames). But that's one of the cool things about templates—you don't have to know exactly how they work to use them. In many cases, you can make simple modifications without getting knee-deep in the mechanics.

The Simple Photo Album template (Figure 7-32) is a perfect example of a template you can use without completely understanding all the ActionScript code and other techniques that make it work. You can even customize it, which this section shows you how to do.

Here are the steps for customizing the template with your own photos:

  1. Choose File→New→Templates and then, under Category, choose Media Playback. Under Templates, choose Simple Photo Album, and click OK.

    The template opens, showing text, buttons, and an image. The brief instructions for using the template appear in red below the stage.

  2. Press Ctrl+Enter (⌘-Return) to test the animation.

    Flash Player shows an image that looks like video color bars with the big number 1. The text above the image says "Image Title 1." Three familiar-looking buttons control the animation. The center button is a Play/Pause button, and the other buttons move the album forward or backward one image.

  3. Close the Flash Player window.

    When Flash Player closes, you're back in Flash Professional.

  4. In the timeline, click the Show/Hide button for the instructions.

    A red X appears when the instructions are hidden.

  5. Click the Show/Hide button for the Controls layer.

    A red X appears when the three control buttons are hidden. When you're investigating a new template, you can learn what's on each layer by toggling the Show/Hide button for each layer. In this case, you learn that the controls are on one layer and that the images and text are on the Images/Titles layer. The Matte layer is a rectangle that's partially hidden by the image. When the image is visible, it looks like a border around the image. The background creates the dark-gray stage color.

  6. Drag the playhead to Frames 2, 3, and 4.

    Each frame on the timeline corresponds with one of the images. That means you can swap your own images for the numbered color bar pics.

  7. Move the playhead to Frame 1, and then click the color bar image on the stage.

    When the image is selected, the Properties panel shows that it's a bitmap, and it's an instance of image1.jpg.

  8. Examine the Position and Size properties.

    Adobe may change the templates from time to time, but the position is probably something like X: 70 and Y: 35. Those settings indicate the position of the upper-left corner. The size properties are probably about: W: 500 and H: 376. If you want to add your own pics, they should be about the same size or at least the same proportions: 500 x 376 pixels.

  9. Prepare your own images for a new album.

    You can resize photos or images within Flash, but you'll probably have best results if you crop your images before you bring them into Flash using a program like Photoshop, The GIMP, or iPhoto.

  10. Choose File→Import→Import to Library and then select your photos and click Open.

    Shift-click or Ctrl-click to select more than one photo for importing. After you click Open, the Import to Library window closes, and your photos are added to the Library.

  11. In the Library, select your photos and drag them to the Sample Images folder.

    Click to open the Sample Images folder, and you can see the individual color bar photos. You might as well put your own pics in there, too, as shown in Figure 7-33.

  12. Select the instance of image1.jpg on the stage.

    Make sure the playhead is on Frame 1 in the timeline and the Properties panel says "Instance of: image1.jpg" as shown in Figure 7-34.

  13. In the Properties panel, click the Swap button.

    The Swap Bitmap window opens.

  14. Open the Sample Images folder and select one of your new images and then click OK.

    Your image appears on the stage. If it doesn't look exactly right, you may need to tweak the size or position settings.

  15. Set the size and position to match the settings you noted in step 8.

    This example had a position of X: 70 and Y: 35 and a size of W: 500 and H: 376.

  16. Repeat the swapping process for each photo you want to add.

    Each frame should display one of your photos.

  17. For each frame, double-click the top title and type your own title for the image.

    You can double-click with the Selection tool (V) to open the text for editing.

  18. Press Ctrl+Enter (⌘-Return) to test the animation.

    Your customized animation plays, showing your own photos and text.

The preceding steps work great if you want to create a photo album with exactly the same number of pics as the template. Suppose you want to add one more image to the album. You can do that easily and without digging into the ActionScript code that makes the album work. All you have to do is extend the timeline in a few places.

The top two layers in the timeline are named Instructions and Actions. You can delete the Instructions layer once you're done reading it. The Actions layer holds the ActionScript code for the album. You can learn more about writing your own code on Customizing the Video Playback Component, but for now, you can leave the Actions layer the way it is. The next layer moving down is the Controls layer. You want the Play/Pause and Forward and Back controls to appear with every photo, so you need to extend the Controls layer. Select Frame 5 and then press F5 to insert a frame (Inserting and Deleting Keyframes and Frames). Do the same for the Matte layer and the Background layer. You need a new keyframe in the Images/Titles layer because you want both to change, so press F6. The newly created keyframe holds that last image and title in the album. All you need to do now is swap them for the new photo. You can repeat this process to add as many photos as you want to the album (Figure 7-35).

Once you start cooking in Flash, you'll have a bunch of animations that you want to turn into templates. As they say, why reinvent the wheel? Templates are great timesavers, and it's easy to create your own. For now, you may want to experiment with a file from the Missing CD (www.missingmanuals.com/cds), such as 07-5_Photo_Gallery.fla. This example, shown in Figure 7-36, is a lightbox-style photo gallery. Click a thumbnail image, and it flips around a bit and then fills the stage. Another click, and the photo shrinks back to a thumbnail. The gallery holds nine photos total. If you save the photo gallery as a template, you can open it and swap the sample photos with your own masterpieces.

First, open the standard .fla file. It's all ready to go, and it even has some instructions in the top layer that appear above the stage. If you want to see the photo gallery in action, press Ctrl+Enter (⌘-Return).

To save the Flash document as a template, choose File→Save As Template. A dialog box appears with a warning that explains that the "SWF history" will be cleared when the file is saved as a template. Go ahead and click the Save As Template button. The next thing you see is the Save as Template box shown in Figure 7-37, where there's room for a Name, Category, and Description. The Preview window shows the stage for the template. Fill in the details you want, and then click Save. Flash saves your file as a template. The next time you choose File→New and click the Templates tab, you'll see your saved template along with all the others.