Home : Adobe : Flash : Actionscript : Trace

Trace

The trace command is a very useful tool for Flash development. It doesn't actually do anything in the finished movie — it's role is to provide tracking and debugging information during development of the movie.

The trace command looks like this: trace();

Here's how it works:

Flash Output Window

A value in quote marks is a string literal, that is, it will be displayed exactly as entered. An example of this usage is to confirm that a certain part of the script has been run, or to see which branch of a script is run, like so:

function calc1() {
trace("calc1 is executing");
  if (my_condition) {
   trace("my_condition is true");
  } else {
   trace("my_condition is false");
 }
}

A value without quote marks is either a number or a variable. Tracing variables is a very powerful and flexible way to see what's happening in the movie. The following example traces two values — a variable called my_num and the number of the current frame:

var some_variable = 119;
var my_num = (some_variable+1)/10;
trace(my_num);
trace(this._currentframe);

This gives the following output (note that each trace appears on a new line):

Flash Output Window

If you want to keep track of a number of variables, it's a good idea to add descriptive strings to make them easier to follow. For example:

var some_variable = 119;
var my_num = (some_variable+1)/10;
trace("my_num: "+my_num);
trace("Current Frame: "+this._currentframe);

This gives the following output:

Flash Output Window

Whether or not you are having problems with your Flash/Actionscript, it's a good idea to get used to using the trace command. Especially if you are new to Flash, tracing gives you a lot of information and helps you to understand how your movies work.

Note: The trace command has no effect in the finished movie but it is good practice to remove (or comment) all traces before publishing.