This is one useful utility for tracing objects in ActionScript 3 code. The name of the class is just t (from tracer). I find that short name easier to type. If you have the interface mx.collections.IList you can download it from here or if you don't from here

So if you want to trace just a string you can use it as:

t.str("some string");

// the trace: 
// some string

or you can use multiple arguments:

t.str("some string", 15, true);

// the trace: 
// some string | 15 | true

or if you have an object defined for example like this one:

var obj:Object = {
    first:123,
    second:"qweqwe",
    third:[
      "aa",
      "bb",
      "cc",
      {
        innerOne:23,
        innerTwo:[1,2,3]
      }
    ]
  };

you can trace it as:

t.obj(obj, "this is ", 1, " object");
  /* the trace: 
  -------------------------
  this is  | 1 |  object
  Object type is: [Object]
  Object content is: 
  {
    third: [
      /*0*/"aa",
      /*1*/"bb",
      /*2*/"cc",
      /*3*/{
        innerOne: 23,
        innerTwo: [
          /*0*/1,
          /*1*/2,
          /*2*/3
       ]
      }
    ],
    first: 123,
    second: "qweqwe"
  }
  -------------------------
  */

The trace that is produced is not just an object description but also a valid code that you can copy and paste to instantiate that object in case you want to modify some properties for the purpose of debugging.

And if you want to trace just a specific number of levels you can use:

t.lev(obj, 2, "this is a ", true, " object");
  /* the trace: 
  -------------------------
  this is a | true |  object
  Object type is: [Object]
  Object content is: 
  {
    third: [
      /*!!!-The maximum limit of 2 levels to trace has been reached-!!!*/
    ],
    first: 123,
    second: "qweqwe"
  }
  -------------------------
  */

here the number of levels is set to 2.

If you are inside a deeply nested function and you want to understand how you got there you can use:

t.str(t.stack)

The object also broadcasts LocalConnection. If you want to make another movie to listen to this connection use:

var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.Add = function(trace:String) {
    // here you can present trace the way you want
};
receiving_lc.connect("__FlashTracer");

If you want to make it stop broadcasting data, use in the beginning of your code:

t.DoNotBroadcast = true;

If you want to make it stop tracing, use in the beginning of your code:

t.DoNotTrace = true;

And if you want to use this tracer to debug files on a remote server you can download ServerTracer.swf from here. Then put that swf file on the same folder on the server where is the file you want to debug (the file where you've used t.str() t.obj() or t.lev()). Open in a browser ServerTracer.swf and then load your file. You will see the trace comming.

Share this post:   digg     Stumble Upon     del.icio.us     E-mail

Letharion
Posted on 9/1/2007 3:41:24 AM

Very useful, thank you very much :)

Vladimir Bodurov
Posted on 9/5/2007 4:30:37 PM

Thanks, I've changed it to make it parse also the object accessors.

Letharion
Posted on 9/9/2007 11:24:46 AM

Downloaded the latest version. t.obj(myCustomClassHere) sometimes gives.

"Error: Error #2071: The Stage class does not implement this property or method.
at Error$/throwError()
at flash.display::Stage/get textSnapshot()
at ::Tracer/::parseProperties()
at ::Tracer/::parseHierarchicalStructure()
at ::Tracer/::parse()
at ::Tracer/::parseProperties()
at ::Tracer/::parseHierarchicalStructure()
at ::Tracer/::parse()
at ::Tracer/::parseProperties()
at ::Tracer/::parseHierarchicalStructure()
at ::Tracer/::parse()
at ::Tracer/::parseProperties()
at ::Tracer/::parseHierarchicalStructure()
at ::Tracer/::parse()
at ::Tracer/::parseProperties()
at ::Tracer/::parseHierarchicalStructure()
at ::Tracer/::parse()
at ::Tracer/::parseCollection()
at ::Tracer/::parseHierarchicalStructure()
at ::Tracer/::parse()
at ::Tracer$iinit()"

Vladimir Bodurov
Posted on 9/9/2007 1:12:50 PM
Nicoás Parziale
Posted on 9/1/2008 11:40:29 AM

It's a great tracer!! Thanks for sharing it.

Anthony Maitz
Posted on 8/25/2009 8:23:37 PM

This is an amazing help. You're a lifesaver.

Ronnie Swietek
Posted on 10/13/2009 4:46:08 PM

Nice little class you got there. I was working with the array.sortOn() method and this class helped me work out all the kinks...thanks!

Nico Limpika
Posted on 10/30/2009 6:00:16 PM

This also helped me alot when doing some debugging inside of the browser. I was able to parse out object data from the stack trace. Instead of direct access to the object.
http://www.actionscript-flash-guru.com/blog/18-parse-file-package-function-name-from-stack-trace-in-actionscript-as3

Yasin Masukor
Posted on 11/5/2009 5:44:52 PM

This is the most amazingly helpful class I've come across for some time. Thanks

SmivaL
Posted on 11/12/2009 3:12:40 AM

Спасибо, Владимир!

Bridh
Posted on 3/1/2010 7:39:46 PM

After importing this package i can view all my object properties.

well done.

toto
Posted on 3/6/2010 10:21:00 PM

this rocks, thanks :¬)

Znt
Posted on 6/12/2010 2:37:07 AM

awesome job, helped greatly.

Paolo
Posted on 7/20/2010 1:27:30 AM

Thank you Vladimir for your great work. Just one feedback more.
I'm using version 1.1 of your tracer and I found a very strange behaviour implementing it in conjunction with FileReference Class calls.

If I run my flash file from inside flash 9 ('try movie' or 'debug' mode), the the file chooser dialog appears as expected but if I publish the SWF and try to run it by using flash projector or flash player than the FileChooser dialog does not appear. Removing all the "t" class calls all is working fine.

Thanks for your feedback

Paolo

Ray
Posted on 9/23/2010 1:15:48 AM

Hi,Vladimir Bodurov.
Thx for your tracer. It helps anyway.
But when I use this to trace an object which contains functions, I counld't get the function details.Is there any possibility to do this?

Vladimir Bodurov
Posted on 9/23/2010 8:30:22 AM

Hi Ray,

As far as I know Action Script unlike JavaScript does not give you access to the function code. Let me know if you find a way.

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box: