7 May 2012
Prior experience working with Flash Professional CS6 is not required. This introductory article provides all the steps you need to get started. Although this sample project includes some ActionScript code, previous knowledge of programming is not necessary.
Note: If desired, you can download the sample files to review a working version of the completed project. Otherwise, just follow along with the instructions provided below to create the sample project from scratch.
Beginning
Note: For information on how to create your first Flash Professional CS5 document, refer to this article.
Adobe Flash Professional CS6 is an authoring tool that you can use to create games, applications, and other content that responds to user interaction. Flash projects can include simple animations, video content, complex user interfaces, applications, and everything in between. In general, individual projects created with Flash Professional are called applications (or SWF applications), even though they might only contain basic animation. You can make media-rich applications by including pictures, sound, video, and special effects.
The SWF format is extremely well suited for delivery over the web because SWF files are very small and take little time to download. Flash projects often include extensive use of vector graphics. Vector graphics require significantly less memory and storage space than bitmap graphics because they are represented by mathematical formulas instead of large data sets. Using bitmap graphics in Flash projects results in larger file sizes because each individual pixel in the image requires a separate piece of data to represent it. Additionally, Flash allows you to select graphic elements and convert them to symbols—making them easier to reuse and further improving performance when SWF files are viewed online.
To build an application in Flash Professional CS5, you create vector graphics and design elements with the drawing tools and import additional media elements such as audio, video, and images into your document. Next, you use the Timeline and the Stage to position the elements and define how and when they appear. Using Adobe ActionScript (a scripting language) you create functions to specify how the objects in the application behave.
When you author content in Flash Professional (by choosing File > New), you work with the master document, which is called a FLA file. FLA files use the file extension .fla (FLA). While editing a FLA file in the Flash authoring environment, you'll notice that the user interface is divided into five main parts:
The five areas of the workspace are identified in Figure 1.
ActionScript code allows you to add interactivity to the elements in your document. For example, you can add code that causes a button to display a new image when it is clicked. You can also use ActionScript to add logic to your applications. Logic enables your application to behave in different ways depending on the user's actions or other conditions. There are different versions of ActionScript. Flash Professional uses ActionScript 3 when an ActionScript 3 or Adobe AIR file is created, or ActionScript 1 and 2 when an ActionScript 2 file is created in the New Document dialog box.
Flash includes many features that make it powerful but easy to use, such as prebuilt drag-and-drop user interface components, built-in motion effects that you can use to animate elements on the Timeline, pre-written code snippets, and special effects that you can add to media objects.
When you have finished authoring your FLA file, you publish it by selecting File > Publish (or pressing Shift+F12). The publish operation generates a compressed version of your file with the extension .swf (known as a SWF file). Adobe Flash Player is used to play the SWF file in a web browser or as a stand-alone application. Although you don't upload or distribute the FLA file itself, you'll always want to keep a copy of the master document. If you need to make any changes, you can open the FLA file in Flash, edit it, and then publish an updated SWF file.
This tutorial guides you through the process of creating a basic FLA document. You'll use this workflow when authoring projects in Flash Professional. The first step involves creating a new document:
Note: Later, you can create a preset of your own custom workspace by positioning the panels in any way that you prefer. Choose the New Workspace option and enter a name to save your personal configuration. Once it's saved, you can reset the workspace by choosing its name from the workspace menu.
Tip: You can set the background color of the Stage in the Flash movie by choosing Modify > Document or by selecting the Stage and then modifying the Stage color swatch in the Property inspector. There's no need to draw a rectangle to define the background color. When you publish your movie, Flash sets the background color of the published HTML page to the same color as the Stage background color (if you choose to generate an HTML file).
After you've created your Flash document, you are ready to add some artwork to the project. Drawing shapes is a common task in Flash. When you use the drawing tools in the Tools panel, the vector graphics you create can be edited at any time. The following steps describe how to create a circle; later, you'll use this circle to create some basic animation. Follow these steps:
To learn more about the two drawing mode options, see the Drawing modes section of the Flash Professional online documentation.
Note: The Shift key works similarly with other auto shapes; when you press and hold Shift while drawing a shape with the Rectangle tool, you'll create a perfect square.
Tip: If you're drawing your circle and you see only an outline of the shape instead of a fill color, first check to ensure that the stroke and fill options are set correctly in the Property inspector while the circle is selected. If the fill color swatch is set to a color and the stroke is set to No Color, the settings are correct. Next, make sure that the option to Show Outlines is not selected in the layers area of the Timeline. (There are three icons to the right of the layer names: eyeball icon, lock icon, and outlines icon. Double-check that the outlines icon displays a solid fill and not just a square outline. If you are not sure if the Show Outlines option is enabled, click the icon repeatedly to toggle the visual state between normal view and outline view.)
After drawing some artwork, you can turn it into a reusable asset by converting it to a symbol. A symbol is a media asset that can be reused anywhere in your document without the need to re-create it. Symbols can contain bitmap and vector images and animations, along with other types of content.
It is common to use symbols to create tweened animations. You can also use symbols to store graphic content (as described in the next set of steps). As you become more familiar with Flash Professional, you'll use symbols to structure applications and interactivity using multiple timelines. Symbols are useful for compartmentalizing parts of a project to make it easier for you to edit specific sections later. Follow these steps to create a symbol:
Tip: You can also convert a graphic into a symbol by selecting it and dragging it into the Library panel.
If the Library panel is not open, choose Window > Library to access it. The new symbol is now listed in the Library panel. (When you drag a copy of the symbol from the Library panel to the Stage, the copy on the Stage is called an instance of the symbol.)
In this section, you'll use the symbol in your document to create a basic animation that moves across the Stage:
You noticed that the animation loops by default as the movie plays in Flash Player. This occurs automatically because in Flash Professional, the Timeline is set up to loop back to Frame 1 after exiting the last frame—unless you instruct the movie to do otherwise. When you want to add a command that controls the Timeline, you'll add ActionScript code to a keyframe (indicated by a dot symbol) on the Timeline. This is known as adding a frame script.
Tip: Keyframes are used to place ActionScript and assets on specific frames in the Timeline. When you review the Timeline of a FLA file, you can locate scripts and content by looking for the keyframe dots. Keyframes that have frame scripts display a lower case "a" symbol.
Follow the steps below to add ActionScript code to your FLA file. You'll add one of the most common Timeline commands, which is called the stop action:
stop();
Note: This step assumes that you're using the default mode of the Actions panel. If the Actions panel is in Script Assist mode, it won't allow you to type directly into to the text area. To return to the default mode, uncheck the magic wand icon in the upper right corner of the Actions panel.
When you are finished creating your FLA file, and you've tested it repeatedly, you are ready to publish it. The files that you output when publishing can be uploaded to a host server so that the project can be viewed in a browser. When you publish the file, Flash Professional compresses the data in the FLA file and generates a much smaller, more compact (and non-editable) SWF file. It's important to note that the FLA is your master, authoring file. Always keep the FLA file handy in case you need to make changes to the project. The SWF file that is generated by Flash when you publish a project is the file that you'll embed in a web page. If you are familiar with Adobe Photoshop, you can think of the FLA file as the equivalent of a master PSD file, and the SWF file as the equivalent of the exported JPEG file that will be inserted on a web page.
While you can choose to edit the publish settings and only publish the SWF file (and then use Adobe Dreamweaver or another HTML editor to insert the SWF file in a page) the Publish command makes things even easier. You can set the publish settings to automatically generate an HTML file that contains the code to embed the SWF file for you.
Follow these steps to publish the FLA file and output the SWF file with the HTML file, so that you can view the published project in a browser:
Tip: You can change the Target field in the top right of the Publish Settings dialog box to target different versions of the Flash Player or the AIR runtimes. Publishing to AIR provides an easy way to create desktop or mobile applications from your web-based application without doing extra work.
You've successfully completed your first FLA file. To learn more about publishing your document, read the Publishing and Exporting section in the Flash Professional online documentation.
In an earlier section, you stopped the animation from looping by adding a stop() action to the last frame of the Timeline. When the playhead reaches the last frame, it is instructed to stop, which prevents it from looping back to Frame 1.
In this set of instructions, you'll learn how to add a Replay button. When a user clicks the button, it causes the playhead to begin playing from Frame 1 again. This is the behavior of the example shown in Figure 19.
Flash is extremely flexible. There are many strategies that you could use to create a Replay button, including restarting the playhead when a user presses a key on their keyboard, or when they click on the Stage, or when they click a button. To achieve any of these options, you'll add some ActionScript code that responds to the user interactivity at runtime (while the SWF file is playing). This section is a little more advanced than the previous sections—it covers some new concepts that you'll use to control the behavior of your Flash movies with programming.
Follow these steps to add a Replay button and the corresponding ActionScript to your file:
Note: One of the most common mistakes is to enter the name of a frame label, rather than entering the instance name of an object on the Stage. Be very careful to always select the object on the Stage first. Then you can access the Property inspector to check that the panel refers to the selected symbol and indicates that an instance is selected. Verify that the field says "<Instance Name>" before you type the name of the instance. If the Property inspector refers to a frame, it means you've accidentally clicked the Timeline. Naming instances can be confusing until you are familiar with the options presented for selected symbol instances and selected keyframes. One thing to check: If you accidentally enter a name in the Property inspector while a keyframe is selected (instead of an object on the Stage), you'll see a red flag icon appear in the Timeline on the keyframe. Frame labels can be very helpful when creating navigation that jumps to different frames in the Timeline; for this example, however, it is critical that you select the button on the Stage and enter the instance name of the button in the button layer as replay_btn. Also make sure there are no typos; otherwise the script will not work.
import flash.events.MouseEvent;
function onClick(event:MouseEvent):void
{
gotoAndPlay(1);
}
replay_btn.addEventListener(MouseEvent.CLICK, onClick);
onClick. The last line of code uses theaddEventListener method, which registers the function as an "event listener" for the button's "click" event. The translation of this code essentially says: "When a user clicks the button named replay_btn, run the function named onClick. When the onClick function runs, it instructs the playhead to jump to Frame 1 of the Timeline and begin playing the frames."This is the standard format used when writing ActionScript 3; one section checks for user interactivity (such as a mouse click) and that triggers another function to respond to timing cues from objects in Flash Player. In this case, the event handler function instructs Flash Player to return to Frame 1 and start playing the Timeline again. (You'll use a similar syntax of creating an event handler function and assigning it to a button instance any time you create an interactive button in Flash.)
Tip: You can use the Code Snippets panel as a shortcut when adding events to buttons.
There are many online resources you can use to learn more about working with Flash Professional:
Flash User Forum |
More |
| 04/23/2012 | Auto-Save and Auto-Recovery |
|---|---|
| 04/23/2012 | Open hyperlinks in new window/tab/pop-up ? |
| 04/21/2012 | PNG transparencies glitched |
| 04/01/2010 | Workaround for JSFL shape selection bug? |
Flash Cookbooks |
More |
| 02/13/2012 | Randomize an array |
|---|---|
| 02/11/2012 | How to create a Facebook fan page with Flash |
| 02/08/2012 | Digital Clock |
| 01/18/2012 | Recording webcam video & audio in a flv file on local drive |