Add interactivity with code snippets, Before you begin, Add a code snippet to an object or timeline frame – Adobe Flash Professional CC 2014 v.13.0 User Manual
Page 37
Add interactivity with code snippets
Before you begin
Add a code snippet to an object or Timeline frame
(Flash CS5.5) Add a code snippet to an object or Timeline frame
Add new snippets to the Code Snippets panel
The Code Snippets panel is designed to make it easy for non-programmers to start using simple JavaScript and ActionScript 3.0 quickly. It lets
you add code to your FLA file to enable common functionality. Using the Code Snippets panel does not require knowledge of JavaScript or
ActionScript 3.0.
With the Code Snippets panel, you can:
Add code that affects the behavior of an object on the Stage
Add code that controls the movement of the playhead in the Timeline
(CS5.5 only) - Add code that allows touchscreen user-interaction
Add new code snippets that you create to the panel
Using the code snippets included with Flash is also a good way to begin learning JavaScript or ActionScript 3.0. By looking at the code in the
snippets and following the snippet instructions, you can begin understanding code structure and vocabulary.
Before you begin
When working with the Code Snippets panel, it is important to understand these fundamentals of Flash:
Many of the code snippets require you to customize a few items in the code. In Flash Pro you can do this in the Actions panel. Each snippet
contains specific instructions for this task.
All of the included code snippets are either JavaScript or ActionScript 3.0.
Some snippets affect the behavior of an object, allowing it to be clicked or causing it to move or disappear. You apply these snippets to the
object on the Stage.
Some snippets cause an action to occur immediately when the playhead enters the frame that contains the snippet. You apply these snippets
to a Timeline frame.
When you apply a code snippet, the code is added to the current frame of the Actions layer in the Timeline. If you have not created an
Actions layer yourself, Flash adds one above all other layers in the Timeline.
For ActionScript to control an object on the Stage, the object must have an instance name assigned in the Property inspector.
You can click the Show Description and Show Code buttons that appear when you select a snippet in the panel.
Additional videos and tutorials
(12:11, Adobe TV)
(10:20, flashandmath.com)
Tutorial:
Add a code snippet to an object or Timeline frame
To add an action that affects an object or the playhead:
1. Select an object on the Stage or a frame in the Timeline.
If you select an object that is not a symbol instance, Flash converts the object to a movie clip symbol when you apply the snippet.
If you select an object that does not already have an instance name, Flash adds one when you apply the snippet.
2. In the Code Snippets panel (Window > Code Snippets), double-click the snippet you want to apply.
If you selected an object on the Stage, Flash adds the snippet to the Actions panel in the frames containing the selected object.
If you selected a Timeline frame, Flash adds the snippet to just that frame.
3. In the Actions panel, view the newly added code and replace any necessary items according to the instructions at the top of the snippet.
30