Join Todd Perkins for an in-depth discussion in this video Working with comments, part of ActionScript 3.0 in Flash CS4 Professional for Designers.
Sometimes you'll want to make notes to yourself in a code or maybe a note to somebody else who is going to see your code later. Also, you may want to temporarily disable a block of code. You can do that all using comments. In this movie we will talk about how to use comments in the ActionScript. If you are following along open up Comments.fla or just use a blank file. Go to the first keyframe of the Actions layer and open up the Actions panel with Options+F9 on the Mac or F9 on the PC. Here I have a Trace Statement. Let's say I wanted to make a note to myself what a Trace Statement does. I am going to put my cursor right before the word trace and press Enter or Return to kick it down a line and then go up one line.
To make a comment, type two forward slashes. You will that the forward slashes turn gray and any text that I type on this line will not get processed as ActionScript code. So I can put information like 'trace statements make a message appear in the Output window!' So using two forward slashes you can disable a single line of code. If you want to re-enable that line of code, you can always delete the forward slashes.
You can do that by selecting the forward slashes and deleting them. Note that the keywords that are reserved by ActionScript are highlighted in blue in the code now. If I were to test the movie right now, I would run into some errors in my code. Another way to add a single line comment is to put your cursor where you want to insert the forward slashes, and then click the Single Line Comment button in the Actions toolbar. It looks like a bubble with two forward slashes in it. So you click that, and then we can disable that line of code. Another way to delete comments is to use the Remove Comment button in the ActionScript toolbar.
It looks like a bubble with a red X at the top. So if I click that button, the comment is removed. Let's say I wanted to comment on multiple lines at the same time. All that you have to do is use forward slash and then an asterisk to begin the multi-line comment. So I will start that at line 1, and at the end of the comment use an asterisk and then a forward slash. So I can have a comment that runs as many lines as I would like. So you start it again with forward slash asterisk and you end that with asterisk forward slash. Now I am going to remove this comment by selecting this whole block of code, and then I will click the Remove comment button. Now, if I want to quickly apply a multi-line comment, I could select a range of text, so I will select lines 1 and 2, and then you just click Apply Block Comment button. That is the bubble with a forward slash and an asterisk inside of it in the ActionScript toolbar. Click that button and the muti-line comment is applied.
So using comments you can make notes to yourself and you can temporarily disable lines of code. All you have do is use two forward slashes, or the Single Line Comment button to apply a single line comment, and then forward slash asterisk to begin a multi-line comment, and asterisk forward slash to end a multi-line comment.
- Working with loops to show repeated actions
- Defining functions and variables
- Handling events and event listeners
- Using classes to organize code
- Building arrays to hold lists of information
- Loading external content from various files
- Adding images and sound to an application
Skill Level Intermediate
Q: After creating a preloader as shown in the "Creating a preloader" movie, an error message reading "Error #1009: Cannot access a property or method of a null object reference" appears when the preloader is placed in the timeline. How can this issue be resolved?
A: There is most likely a typo in the code. Unfortunately, Error 1009 is the most vague error in Flash and means the code trying to reference an object that doesn't exist (hence the likeliness of a typo). The best fix is to go through the code one character at a time to make sure everything is correct.
1. Introducing AS3.0 Fundamentals
2. Working with Variables
3. Using Functions
4. Working with Display Objects
5. Understanding and Handling Events
6. Creating Conditional Statements
7. Using Math to Perform Tasks
8. Creating and Using Arrays
9. Creating and Using Loops
10. Using Classes
11. Handling Text
12. Loading Media
13. Creating a Calculator
14. Getting Out of Trouble
Getting help3m 26s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.