Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

Adobe Flash CS6 Classroom in a Book: Creating a Home Button with Code Snippets

  • Print
  • + Share This
In this excerpt from Adobe Flash Professional CS6 Classroom in a Book, you'll learn to use the Code Snippets panel to add ActionScript to your project.
From the book

A home button simply makes the playhead go back to the first frame of the Timeline, or to a keyframe where an original set of choices, or the main menu, are presented to the viewer. Creating a button that goes to frame 1 is the same process as creating the four restaurant buttons. However, in this section, you’ll learn to use the Code Snippets panel to add ActionScript to your project.

Adding another button instance

A home, or main menu, button is provided for you in the Library panel.

  1. Select the Buttons layer and unlock it if it is locked.
  2. Drag the button called mainmenu from the Library panel to the Stage. Position the button instance at the top-right corner.
  3. In the Properties inspector, set the X value to 726 and the Y value to 60.

Using the Code Snippets panel to add ActionScript

The Code Snippets panel provides common ActionScript code that makes it easy for you to add interactivity to your Flash project, and simplifies the process. If you are unsure of your ability to code your own buttons, you can use the Code Snippets panel to learn how to add interactivity. The Code Snippets panel gives you a preview of the actual code, allows you to modify the critical parameters of the code, and use a visual pointer, called the pick whip, to point to objects on the Stage.

You can also save, import, and share code between a team of developers to make the development and production process more efficient.

  1. Select the first frame of the actions layer in your Timeline. Choose Window > Code Snippets, or if your Actions panel is already open, click the Code Snippets button () at the top right of the Actions panel.
  2. The Code Snippets panel appears. The code snippets are organized in folders that describe their function.

  3. In the Code Snippets panel, expand the folder called Timeline Navigation and select Click to Go to Frame and Stop.
  4. Immediately to the right of the code snippet name you’ll find a description button and a code button.

  5. Click the description button.
  6. A brief description of the selected code appears.

  7. Click the code button.
  8. The actual code appears. There is a commented portion of the code that describes the function of the code and the different parameters. The colored parts of the code are the parts that you need to change.

  9. Move your mouse over the blue words instance_name_here.
  10. Click and drag your cursor from the blue code words to the Home button on the Stage.
  11. A purple line extends from the Code Snippets panel to the Home button. The Home button becomes highlighted with a yellow border, indicating that the selected code snippet will be applied to it.

    If you point your pick whip to an object that doesn’t support the particular code snippet, a circular icon with a diagonal line appears (the international “no” symbol).

  12. Release your mouse cursor.
  13. Since you have not yet named the Home button, a dialog box appears to allow you to give a name to the instance.

    The instance name of the Home button is added to the code.

    If you pointed your pick whip to an object that doesn’t support the particular code snippet, your pick whip will rebound and the code snippet will remain unmodified.

  14. Highlight the blue number within the parentheses in the code.
  15. The blue number indicates which frame of the Timeline that Flash will display when you click on the Home button.

  16. Replace the blue number with the number 1.
  17. Click Insert.
  18. Flash adds the code snippet to the current keyframe on the Timeline. A flag appears on the Timeline to let you know that the code has been added, and to indicate where on the Timeline it’s been placed.

    Click on the flag to open the Actions panel to view the code. You should be familiar with the syntax since you hand-coded your restaurant buttons earlier in this lesson. The Code Snippets panel, however, can make adding code quick and easy.

  • + Share This
  • 🔖 Save To Your Account