Getting Started - Trace Function PDF Print E-mail
Written by Smash   
Wednesday, 15 July 2009 20:35

What is the Trace Function?

The trace function is a simple function in ActionScript that by itself does not really add much of anything to our Flash projects, however, it can be used to test out our programming (like seeing if a section of code ever gets processed) or see what is currently contained in a variable while a Flash project is running.

When you use a trace function it puts what you send to it into the output box when you run your Flash project.

a trace function is created like this

trace("Hello World");

you can also use a trace function to see inside a variable like this (the variable being myNum)

Don't worry if this code looks complicated right now, im just using it to illustrate a point

for(var myNum:Number=0; myNum<10; myNum++)
{
 trace(myNum);
}

this code basically loops the function 10 times adding 1 to the variable each time, the output for this would be

0 1 2 3 4 5 6 7 8 9.

Try these examples out in your own projects. Here is a video showing exactly what I mean.

 

 
Home > Tutorials > ActionScript 3.0 > Getting Started - Trace Function