Adobe
flashthusiast.com
Welcome to Part 2 of this three-part introduction to Macromedia Flash. You survived Part 1 of this tutorial, where you created, set up, and imported content into a FLA file. Because you're reading Part 2, you're probably ready to learn more about Flash. That's good because more fun ensues in this part—you will create symbols, animation, and even write some simple ActionScript to make the banner function.
Note: If you are still using Flash MX 2004 and not Flash 8, please see the previous version of this article.
To complete this tutorial you will need to install the following software and files:
Using Flash for the First Time – Part 1: Building a Banner
You need to add some text to your banner for decorative purposes. You can add several types of text to a Flash document: static text, dynamic text, or input text. Static text is useful when you need to add decorative text to the Stage, or any text that doesn't need to change or load from an external source. Use dynamic text when you want to load text from a file or database, or change the text when the SWF file plays in Flash Player. Use input text when you want the user to type into a text field. You can take that text and send it to a database, have it manipulate something in the SWF file, and more.
You can add any of these types of text using the Text tool. For this exercise, you will add some static text to the Stage. To add static text, follow these steps:
Open the banner.fla document you created in Part 1 of this tutorial, and rename the file banner2.fla.
Note: If you didn't finish Part 1 of this tutorial, or lost your file, open the folder of the source files ZIP archive that accompanies this tutorial. Inside the start folder, find banner2.fla and use this file to begin the tutorial.
Select the text field.
A bounding box appears around the text when you select it.
Change the font of the text to whatever font you prefer.
You change the font using the Font pop-up menu (next to the A icon, seen in Figure 1).
Change the size of the font to 24 points using the Font size pop-up menu. You will need to change the font size so the text fits on the Stage.
Figure 1. Change text settings in the Property inspector.
When you finish, the text should look similar in size and position to the text in Figure 2.
Figure 2. Add some static text to the banner.
Repeat Steps 6 and 7 to add the phrase Gnome? below the previous two lines of text.
When you finish, your banner will resemble Figure 3.
Figure 3. You should have three lines of text that resemble this image when you finish this exercise.
Tip: For advanced text effects, you can create text in Macromedia FreeHand, save the file, and import it. If you're using Adobe Illustrator, you can export the text as a PNG or SWF file. You can then import this text into Flash.
A symbol is an object that you create in Flash. As you discovered in Part 1, a symbol can be a graphic, button, or movie clip that you reuse throughout the current FLA or other FLA files. Any symbol that you create is automatically added to the document's library (Window > Library), so you can use it many times within a document.
When you add animation, you should always animate symbols in Flash instead of animating raw graphics (graphics that you draw) or raw assets that you import (such as a PNG file). For example, if you draw a circle using the Oval tool in Flash, you should convert that circle graphic into a movie clip before you animate it. This helps you reduce the SWF file size and makes it easier to create an animation in Flash.
You will create a movie clip symbol in the following exercise. You will animate this movie clip in later exercises.
In banner2.fla, select the star.png image (imported in Part 1) and then select Modify > Convert to Symbol from the main menu.
The Convert to Symbol dialog box opens (see Figure 4), where you can name a symbol and choose what type of symbol you want it to be.
Type join us into the Name text box (see Figure 4).
You will see the name of the symbol, join us, in the Library panel after you create the symbol. You will also see an icon that represents movie clips next to the symbol's name.
Remember that the symbol's name is different than its instance name because you can have numerous instances of a single symbol on the Stage. For example, you can set an instance name for the join us symbol using the Property inspector after you drag it to the Stage from the Library panel. If you drag another instance of join us to the Stage, you assign it a different instance name. You use the instance name in your ActionScript to reference and manipulate the instance with code, and there are some naming guidelines you must follow when you assign an instance name. (I'll discuss these later in this tutorial, in the section Writing Simple Actions).
Figure 4. Use the Convert to Symbol dialog box to convert selected content into a symbol, give it a name, and add it to the document's library.
Select the Movie Clip option and then click OK.
This means that you will convert the graphic image into a movie clip symbol. Movie clip symbols have their own Timelines. This means you can animate each movie clip instance on its own Timeline, and on the main Timeline of the document. This is unique to movie clip instances.
In the following exercise you will animate the movie clip.
You have already used the Timeline in Part 1 of this tutorial to insert new layers and add content onto those layers. In Part 1 you added assets to a frame on the Timeline. You might have noticed that after you add content on a frame, a filled circle appears on the frame to signify content on that frame. Whenever there's new or changed content on a frame, it's called a keyframe and has a filled black dot on the frame. A keyframe is a frame where you define changes in the animation, or a frame that has content on it. An empty keyframe has a hollow circle. For more information on different kinds of frames, do a search on "frames and keyframes" (with quotes) in the Help panel (F1).
You create an animation in a Flash document by adding content to the Timeline. When the playhead moves across the Timeline, those individual frames play; when they're played in quick succession (like a flipbook or succession of frames on a reel of film), you can create an animation.
When you create a frame-by-frame animation, every frame is a keyframe. In a tweened animation, you define keyframes at significant points in the animation and let Flash create the contents of frames in between. Flash displays the interpolated frames of a tweened animation as light blue or light green with an arrow drawn between keyframes. Because Flash documents save the shapes in each keyframe, you should create keyframes only at the points in the animation where something changes.
To create a frame-by-frame animation, follow these steps:
Select Modify > Document.
The Document Properties dialog box opens. This is the dialog box you used to change the dimensions of the banner in Part 1. Now you want to change the frame rate for the banner.
A higher frame rate means that your animation plays smoothly, more so than when you had it set to 12 frames per second (fps). Changing the fps setting means that the main Timeline and movie clip Timelines all play at the specified frame rate.
Note: An increased frame rate also means that there is a slightly increased demand on the user's computer (or CPU) to render the extra frames each second.
Double-click the join us symbol instance on the Stage.
This opens the symbol in symbol-editing mode (see Figure 5). In this mode, you see the movie clip symbol's Timeline, which runs independently of the Timeline for the main FLA document (the one you saw prior to double-clicking the symbol). This means you can have animations that play and stop independently from animations on the main Timeline. Remember that a movie clip still plays at the document's frame rate (18 fps).
Figure 5. In Symbol-editing mode, the symbol you're editing appears normal, while other items on the Stage are dimmed. Changes you make in this mode apply to every instance of the symbol in your FLA file.
When you enter this mode, it means you edit the symbol itself, not just the single instance on the Stage. Any changes you make on this Timeline (which is the movie clip's Timeline) apply to every instance of the symbol you use in the FLA file.
You can tell that you're editing a symbol by looking at the edit bar (see Figure 6).
Figure 6. Use the edit bar to navigate a document. The edit bar might be above or below the Timeline
Scene 1 refers to the main Timeline of the FLA document. You can click this button to return to the main Timeline. The names after it point to the symbol you're editing. If the symbol is nested within other symbols, this path might contain several names. In Figure 6, you can see that you're editing the join us symbol that's on the main Timeline (Scene 1).
Select Frame 15 and select Insert > Timeline > Keyframe.
Tip: Press F6 to quickly insert a new keyframe.
This command inserts a new keyframe, which means you can modify the content on that frame to create animation. Currently, the content on Frame 15 is duplicated from the content on Frame 1. When you modify Frame 15 in a future step, the modifications won't change the content on Frame 1.
Select the movie clip instance on Frame 15, and then open the Property inspector (Window > Properties > Properties).
Note: Make sure you select the instance on Frame 15, not just the frame. You can first select the frame on the Timeline (or move the playhead to Frame 15) and then select the movie clip instance on the Stage in order to see the correct context of the Property inspector, as shown in Figure 7.
Change the slider value to 75% (see Figure 7).
Figure 7. Change the brightness of the movie clip instance.
The brightness changes for the instance on Frame 15. The instances on Frames 1 and 30 do not change. This means that you can now add a motion tween that animates the brightness value between Frames 1 and 15, and then from Frames 15 to 30. After playing Frame 30, the playhead loops back to Frame 1 and the animation starts again.
Tip: You could also change the alpha or tint values using the same procedure. Alpha tweens are more processor-intensive than tweens that change the brightness or tint of your animation. Try to avoid processor-intensive procedures whenever possible.
Select the instance on the Stage at Frame 15 again, and then select the Free Transform tool in the Tools panel. Select the lower right handle and drag it towards the center of the image to make it smaller (see Figure 8).
Figure 8. Resize the instance using the Free Transform tool.
You can create several kinds of animation in a FLA file. In this tutorial, you will create a tweened animation or motion tween. A motion tween is an animation where you define properties such as position, size, and rotation for an instance at one point in time, and then you change those properties at another point in time. In this animation, you change the brightness and size of the instance.
For information on different kinds of tweens, do a search on "about tweened animation" (with quotes) in the Flash Help panel (F1). You can see examples of different tweens here http://www.flanimation.com/chapters/02/ani_examples/.
Select any frame between Frames 1 and 15, and then select Motion from the Tween pop-up menu in the Property inspector.
The span of frames changes color and an arrow appears between Frames 1 and 15 (see Figure 9). Notice how the options in the Property inspector are different when you select a frame compared to when you select a movie clip instance (see Figure 7 earlier).
Figure 9. Create a motion tween between Frames 1 and 15 on the movie clip's Timeline.
Tip: You can also right-click (Windows) or option-click (Mac) the frame and select Create Motion Tween from the context menu instead.
Tip: A quicker way to test your SWF file is to use keyboard shortcuts. Press Control+Enter (Windows) or Command+Return (Mac) to test the file.
The test environment opens where you can see the animation. Notice how it loops, appearing to fade in and out because of the change in brightness. By default, the playhead returns to Frame 1 and replays the animation after it reaches the final frame on the Timeline. This means the animation loops repeatedly unless you tell it to stop. You will find out how to do this later in the exercise called Writing Simple Actions.
When you create a banner, you need to let your user click anywhere in the banner area and open a new browser window. You can create buttons very easily in Flash. Your button can either have a graphic with rollover graphics, sounds, and even animations of their own. Or you can create an invisible button. Invisible buttons are useful when you want to create "hot spots" on your website or make the entire banner clickable without obscuring your graphics. In the following exercise, you'll add an invisible button over your banner graphics.
Tip: For more information on creating visible buttons with graphics and rollover effects, search "creating buttons" (with quotes) in the Flash Help panel (F1).
Select No Color, as shown in Figure 10. Doing so disables the rectangle's outline.
Figure 10. Select No Color for the stroke color control.
Click and drag the mouse diagonally across the Stage to create a rectangle.
The size of the rectangle does not matter—you will resize it later using the Property inspector.
Click the Selection tool in the Tools panel and then click the rectangle on the Stage to select it.
A cross-hatch pattern appears over the rectangle when you select it.
Open the Property inspector (Window > Properties > Properties). Change the value in the W (width) text box to 160 and the H (height) text box to 600. Then change the X text box and the Y text box both to 0 (see Figure 11).
Figure 11. Change the width and height of the rectangle and then set the location of the rectangle to cover the Stage.
Double-click the new button on the Stage to enter the symbol-editing mode.
The rectangle is currently on the first Up frame of the button you created. This is the Up state of the button—what users see when the button sits on the Stage. Instead, you want the button not to have anything visible on the Stage. Therefore, you need to move the rectangle to the Hit frame, which is the hit area of the button (the active region that a user can click to activate the button's actions).
Click the keyframe at the Up frame and hold down the mouse button while you drag the keyframe to the Hit frame (see Figure 12).
Figure 12. Click and drag the rectangle keyframe from the Up frame to the Hit frame on the Timeline.
Now even though the entire area of the banner is clickable, there is no visual appearance of the button on your banner.
You need to add some simple ActionScript to your banner in order for the invisible button to open a website or send information about how many clicks the banner has received.
There are several different places you can add ActionScript in a Flash document. You can select an instance, and add ActionScript that attaches directly to that instance. To access the code, you would need to find and select that instance again. You can also add ActionScript to a frame (or multiple frames) on the Timeline. It's a good idea to add all of your code to a single frame on the Timeline because it's much easier to find, update, and organize when you're working on a file. Do not attach your ActionScript to instances.
Note: You can also keep your ActionScript in external class files that import into the FLA file you're working on. This is sometimes the best way to organize your ActionScript, particularly when you work on larger projects. This topic goes beyond the scope of this tutorial, however.
Notice how your Join Us motion tween continually loops when you test it. By default, the playhead on the Timeline loops if you have content on more than one frame. Therefore, if you have content on several frames in a movie clip or on the main Timeline, it will play and loop forever. You can stop the playhead from looping by adding a single line of ActionScript. If you add this ActionScript to a frame, the playhead stops when it reaches that frame:
stop();
You don't need to add this ActionScript to your banner. However, you will need to add this ActionScript to other FLA files you create. The stop action is an example of ActionScript that you should be aware of when you use Flash so that you can stop looping SWF files when necessary.
Before you add the code, give the button a unique instance name. The instance name enables you to target the button with ActionScript code. If you don't name the button, your code doesn't have any way of targeting the button from the Timeline. The first step is to assign the invisible button an instance name. Then you can add code that targets that button using its name.
<Instance Name> text box in the Property inspector.Type inv_btn into the <Instance Name> text box.
Note: An instance name is different from the symbols name (which is what you type in the Name text box in the Convert to Symbol dialog box). An instance name cannot have spaces or special characters but can contain underscores. Also, instance names are case-sensitive.
Type the following ActionScript into the script pane (the editable text field) in the Actions panel:
inv_btn.onRelease = function(){
getURL("http://gnome.deseloper.com", "_blank");
};
Notice how you target the inv_btn instance in the first line of code. The event is the onRelease in your ActionScript code, which refers to the action when a user clicks and then releases the mouse over the inv_btn instance. Then you tell the button to open a particular web page (http://gnome.deseloper.com) in a new window (_blank) using the getURL() method. Obviously, you would replace this URL with whatever website you want the banner to open. If you want the banner to open the website in the current page, replace _blank with _self.
This is a simple piece of ActionScript code that reacts to a button click. There is much more information available about the ActionScript language in the Flash documentation (F1). Refer to the documentation's Table of Contents for books and reference guides on ActionScript. A good place to start is Learning ActionScript 2.0 in Flash.
Now you have a Flash banner with graphics and animation, which reacts to button clicks. You have completed your first interactive and animated Flash document!
Let's take a look at it in action, within a browser window:
Select File > Publish Preview (HTML).
The default browser on your computer opens and displays the banner. By default, the banner appears at the upper left corner of the HTML document.
If you are happy with your document, save your changes and proceed to Part 3 of this tutorial. You might want to change the animation or text, or modify the code as necessary.
You now have a banner that you can export and add to a web page. In Part 3 of this tutorial, you will publish your work and take the file and add it to a Dreamweaver website.
To continue to the final part of this tutorial, see Using Flash for the First Time – Part 3: Publishing and Adding a Flash File to a Web Page.
Jen deHaan was raised by wolves in the deep woods of the Canadian north. Later in life, Jen worked with Flash as a deseloper, then wrote about Flash for five versions, and then worked on stuff that didn't include much Flash. She came to her senses in 2007 by rejoining the fabled Flash team at Adobe as a QE, focusing on the good stuff—Motion (on timelines). Jen enjoys long walks in the rain pondering how many times she can use the word Flash in a bio, and admits that after numerous years in California she is no longer addicted to Tim Horton's coffee.