ACA Objective 4.7
If you test the project at this point by choosing Control > Test, you’ll see how well everything has come together. But the animation loops continuously and the actual text message blips by too quickly. You need to stop that playhead so the viewer can read the message.
Working with code in Animate CC
Figure 4.47 The Actions panel
Code Snippets Panel
Working in the Code Snippets panel (Figure 4.48) is a great way for those who are new to working with code to learn how to do some fundamental things in Animate CC projects. The snippets included are divided into three main categories: ActionScript, HTML5 Canvas, and WebGL. These correspond to the target platform you’re working with.
Figure 4.48 The Code Snippets panel
Within these three main categories are a number of additional, functional categories. Every target platform represented has snippets for manipulating the playhead: either stopping the timeline from playing or jumping around to different frames.
It’s best practice in Animate CC to create a layer called Actions where all your frame scripts will be placed. Not only does this make it easy to find any of your code, but it also keeps the code separate from your visual assets that exist in other layers.
Create a new layer and name it Actions.
Insert a blank keyframe on frame 144 (the 6-second marker) by choosing Insert > Timeline > Blank Keyframe.
The only other thing you have to do is write some code in the last frame of your Actions layer to stop the playhead.
With the final frame of the Actions layer selected, open the Actions panel and place the cursor at line 1 (Figure 4.49). Type the following code within the panel:
Figure 4.49 Code entered in the Actions panel
It’s important to understand what this does. In the code, this refers to the present Stage—the main Stage. The instruction stop() tells the playhead on that Stage to stop moving immediately and stay in place, effectively stopping the animation. That’s it! You could certainly use the Code Snippets panel to do this, but it is so simple that typing the code is the more direct route.
Notice on frame 144 that the keyframe has changed. In place of the empty circle, the keyframe now bears a stylized lowercase a that lets you know there is code on that keyframe.