|[ LiB ]|
ActionScript allows you to type in reminders, notes, and comments for yourself right in the program. Why do this? Well, imagine yourself working on a game project for a client for six months. All of a sudden, your client calls on you to make some revisions on the game. That's great and all but, unless it's a small game, you won't remember a lot of the code that you wrote. Even though it's right in front of you, you won't be able to decipher it without spending hours fiddling with it, re-learning how the logic you wrote works. You'll spend more time figuring out how to update and work with your code than actually updating the game like the client originally wanted!
The solution? Comment your code! Comments are like little notes to yourselfor to whomever has to read your code six months down the line. They can help explain complex pieces of code, and they often help you remember what you were trying to do with that logic. The syntax to a comment is actually similar to other languages. When you start a line with a double forward slash (//), you're allowed to write anything you want on the same line. Try to comment anything that you couldn't simply write out. If you had to think before writing the block of code, then comment it! There are no real rules to commenting.
Comments are completely ignored by Flash. They are strictly there for you to read, nothing else. This is why you can type anything you want in a comment without getting a syntax error.
Commenting your code can actually become a valuable skill if you start to work in groups. This cuts down the time that you'll have to explain the code to your team members .
You will see me use a lot of comments in the demo programs to come. Most of the listings in this chapter are not commented because I'm explaining the code directly in the text. Programs so simple that you can guess what they do off the screen generally don't require commenting even though it's great practice.
|[ LiB ]|