ActionScript 3.0 has been available since 2006 and has been enhancing the power of Flash tremendously since then. However, even though most experienced ActionScript programmers would agree that ActionScript 3.0 (AS3) is easier to use than earlier versions of ActionScript, many Flash users have still not yet made the transition to AS3. The main reason cited for this is that many users found AS3 difficult to get started with, and AS3 has lacked good tools to assist beginners. This absence has been rectified with the introduction of the Code Snippets panel in Flash CS5.
A code snippet is a piece of prewritten ActionScript code, usually accompanied by explanatory comments. Flash CS5 ships with dozens of code snippets that allow users to accomplish many of the most common ActionScript tasks without writing a line of syntax. There are code snippets for linking to a URL, navigating the Flash timeline, changing and animating properties of a MovieClip, loading all manner of external content, playing sounds and video, and many other common tasks.
In addition to being a good way to avoid writing any ActionScript, code snippets are a good tool for helping beginners to learn ActionScript. By examining the code that is written using code snippets, beginners can get comfortable with the ActionScript syntax used to perform common tasks. The comments included with the built-in code snippets include instructions for customizing and modifying the code snippets, and from there it is not a big step to writing your own ActionScript files. More experienced programmers can even make their own code snippets for reusing or sharing frequently used chunks of ActionScript code.
The following exercise will introduce you to the basics of working with code snippets.
To begin the example, download the max tutorial file and open the codesnippets_start.fla file from the unarchived folder in Flash CS5. This file has graphics laid out on the stage for a simple interactive project but contains no ActionScript and has no functionality. You will use code snippets to add the functionality to this project.