Comments in ActionScript
'Comment out' notes to yourself within Actionscript code, making it easier to remember what each piece of code is for
Use Actionscript Comments in "Go Rabbit, Go!"

Author: Matt_Slaybaugh
Date: February 15, 2007
Level: Beginner

Summary

Often, programmers need to leave notes for themselves or for others within coding projects. Like most other languages, Actionscript allows comments to be embedded inside the code. These comments provide explanation or guidance for the code to human readers, but are completely ignored by Flash when compiling the code. In this exercise you will learn the different ways to include comments in Actionscript code.

Experience Needed
  • Basic familiarity with Actionscript
Software
  • Flash, any version
Files — Rabbitgame.zip (2.3 MB)
License — "Go Rabbit" (c) 2007, World Wide Workshop Foundation

This software is licensed to the public under the CC-GNU GPL.

Things to know (ActionScript)

Basic familiarity with Actionscript

Description

Open goRabbit.fla. Look at the timeline and notice which frames show a small 'a' (indicated by the red and orange arrows in figure 1). This tells you which frames include Actionscript code.



Click on the first frame in the layer named 'field' (indicated by the red arrow in figure 1).


Make sure the Actions panel is open. If it isn't, open it by selecting Window menu -> Actions.


In the Actions panel you should see the following:


// This section plays until frame 35.

The double-slash ('//') indicates a comment, which is a note to otehr programmers who might be reading the code.
The text is "commented out" and appears gray in the Actions panel.


In the main window, click the large pink rabbit on the right side. You should see the following in the Actions panel:


// this intro section will play until frame 35
// but the user can jump right into the game by hitting the space bar
on (keyPress "") {
gotoAndStop(40);
}

The first two lines are comments, while lines 3 through 5 include Actionscript code.
The double-slash must be placed at the beginning of each line that you want "commented out".
However, there is a second way to indicate comments, the slash-star ('/*'), which is useful if your coments extend over more than one line.


Edit the code in the Actions panel so that it looks like this:


/*
this intro section will play until frame 35
but the user can jump right into the game by hitting the space bar
*/

Remove the double-slash at the beginning of each comment line and place a slash-star ('/*') before the beginning of the comment and a star-slash ('*/') after the end.
You should see that the commented text is gray, just as before.


Save the file.

Producer's Note:
Often, coding projects will sit for days or weeks before you have a chance to return to them. During that time it's easy to forget what a particular chunk of code is for. Like most other languages, Actionscript allows you to annotate your code with notes to yourself, without having Flash try to compile them.