Alternate “Trace” Command in AS2 & AS3

Posted by David Jumeau
Jul 21 2009

I had taken some video tutorials at Flash Extensions.com way back, and I always liked Robert Taylor’s appoach in using the trace command in Actionscript. I would represent this via the “tr” method in each of my classes so that when I am previewing the program, I can know in which class I can find the origin of my trace statements. AS3 is not much different since you can use multiple arguments in your function parameters.

The AS2 version used an undocumented arguments array in the parameters of a function like this:

// This method in a class called MyClass

private function tr(arguments):Void {

  if (arguments.length == 0) {
    trace("");
  } else {
    trace("[MyClass] ... " + arguments.join(" : "));
  }

}

In AS3,

// This method in a class called MyClass

private function tr(... args:Array):void {

  if (args.length == 0) {
    trace("");
  } else {
    trace("[MyClass] ... " + args.join(" : "));
  }

}

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Trackback URL for this entry