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.