Posts By Category

Posts By Date

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     Technorati     E-mail

Feedback

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

Very useful, thank you very much :)

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

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

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()"

Posted on 9/9/2007 1:12:50 PM
Posted on 9/1/2008 11:40:29 AM

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

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

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

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!

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

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

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

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

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

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

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

well done.

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

this rocks, thanks :¬)

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks
Use [code] if(true) alert("OK"); [/code] for source code
 
Enter the text you see in the box: