Watching:

Reviewing the Code Snippets panel


show more Reviewing the Code Snippets panel provides you with in-depth training on Developer. Taught by Todd Perkins as part of the ActionScript 3.0 in Flash Professional CS5 Essential Training show less
please wait ...

Reviewing the Code Snippets panel

Code snippets give you an excellent starting point when writing code, by giving you access to dozens of useful, prewritten blocks of ActionScript. To access the Code Snippets panel, you can click the Code Snippets button in the top-right of the Actions panel, or go to Window > Code Snippets. Now, you're probably already familiar with the Code Snippets panel, so I'm just going to do a quick review. The snippets are organized in categories: regular actions, actions for timeline navigation, for animation, loading and unloading files, et cetera.

Let's say I want to stop the Timeline. I could expand the Timeline Navigation, and double-click stop at this frame. In the Actions panel, you'll see the stop action is added. It says 'stop,' and there's parentheses, and then as semicolon, and there is a comment. You can tell it's a comment because it's gray. Remember that multiline comments start with a forward slash and an asterisk and then end with asterisk forward slash. This comment explains what the code does. Now, you've probably already done this before, if you've ever used the Code Snippets panel.

But another thing you can do with the Code Snippets panel, if you're an advanced user, is create your own code snippets. Let's go back to the Code Snippets panel and see how to do this. To create your own snippet, click the Gear icon at the top-right of the Code Snippets panel. Then choose Create New Code Snippet. Give your code snippet a Title. Give your code snippet a tooltip.

You can autofill from code that's already selected in the Actions panel if you want, or you can simply write your code in the Code area. This code doesn't really do anything, so you don't need to copy it down if you don't want to. Note that you can also check this box to automatically replace instance_name_here when you're applying the code snippet. You may have seen an example of that when you, say select a button, and then use a code snippet to make that link to a web site.

That's what you're essentially doing here. To create the code snippet that does that, you simply type instance_name_here, and Flash will automatically replace that code with the correct instance name when you select it on the stage and apply the code snippet. Keep in mind that if you didn't understand that, it's no big deal. That's something that you're going to understand more about when you learn more about ActionScript. So I'll click OK to create the code snippet, and then you can see my example snippet in the Custom section. So, I'm going to apply it into my code by double-clicking it, and there it is right there.

So if you ever find yourself constantly writing the exact same block of code, see if you can find it prewritten in the Code Snippets panel. If it's not there, you can always add it yourself, so you can save time when creating your projects.

Reviewing the Code Snippets panel
Video duration: 3m 7s 7h 8m Beginner Updated May 23, 2012

Viewers:

Reviewing the Code Snippets panel provides you with in-depth training on Developer. Taught by Todd Perkins as part of the ActionScript 3.0 in Flash Professional CS5 Essential Training

please wait ...