Your First Script / Scripting Convention: Comment Usage
Subtitles of the Movie
As you're writing ActionScript you must develop early the habit of leaving notes to yourself so in this movie let me give you another scripting convention that you need to follow: effective comment usage. At a minimum these notes should explain how certain lines of code work or why you made a particular coding choice. Code comments are a tool that you can use to write text that the computer will ignore in your code. ActionScript includes two kinds of comments, the first is the single line comment. The single line comment like this line right here in the code that we've already worked with is designated by placing two slashes anywhere on the line. Notice that as soon as you add those slashes the line goes light gray. If I remove those slashes notice that the line changes color, in this case the blue words are reserved words that Flash reserves for its own use; this one the name of a function and there the name click. The black words are usually names that you come up with, functions or variables, perhaps instance names, but notice that these colors disappear once I place two forward slashes in front of that code. So this line here will now be ignored by the computer so you can write all kinds of notes to yourself, usually explaining again the lines of code following or some kind of code usage that you need to remember for later. The second type of comment is the multiline comment. The multiline comment includes a starting comment marker, /star, then the comment content and then ending in a comment marker, a star /like so. Let me go down to the bottom of this script here and add a few lines and paste in another comment. Here we go. This might be a really long description, perhaps describing what a particular function is used for or explaining a section of code. Notice that this comment has multiple lines and it starts with this initial comment marker - forward /star and ending with the close comment marker, star /. Now another common use of comments is to temporarily turn off one or more lines of code. For example if you're testing out a different way of doing something or trying to figure out why certain ActionScript code isn't working the way that you expect or to turn off an error that keeps interrupting your playback, for example, let's say that you keep getting an error for line 48 of this script, you can turn off that line of code by placing two forward slashes there. Or perhaps you have a whole section of code that you want to turn off for one reason or another, you could turn off this code. You could also use, remember, the code applying line comments or block comments up here. I can highlight all of this block. Let's go ahead and remove this comment and select this whole section of the code. Click on the Apply Block Comment Tool. Notice that then all of that code block goes gray. You can also turn off the comment using the Remove Comment Tool, very handy. Now another scripting convention that I need to cover is where you can place your scripts. All ActionScript 3.0 scripts must be done or written in frames or external ActionScript files. To make things easier all of your ActionScripts should be placed in your actions layer; all the examples that I provide here will have an actions layer at the top of the layer stack and all my actions will be restricted to that particular layer. Now what this means is that if you've scripted in ActionScript 2.0 before, no more adding of scripts to symbol instances on the Stage, no more object actions will be accepted, so if you're used to scripting your buttons by placing code directly on one of them like the following here, on release and then my actions here, you'll need to prepare yourself for the frame alternatives of this script here in ActionScript 3.0 you must write it out like this using a function, the name of the function, then the mouse event. Your actions are here in between the curly braces and then adding an event listener, which includes the mouse event, the type of mouse event - in this case a click - and then the name of the function button press. This latter script is actually much, much better particularly for beginners since it makes it much easier to find your scripts and then also to debug your errors. Now if you're using Flash 8 or earlier you'll be limited to working with ActionScript 2.0. If you have Flash CS3 or CS4 or a later version, you have the option of using either version of ActionScript 2.0 or 3.0. Let's now proceed to the next Section of this Tutorial, ActionScript Fundamentals Part 1, so I can give you some ActionScript theory and review some of the more important components of ActionScript 3.0.
Tutorial Information
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 