how about traceObject?

11 views
Skip to first unread message

J.Wang

unread,
Oct 23, 2012, 12:30:42 AM10/23/12
to temple...@googlegroups.com
traceObject is useable, but is it deprecate in version 3.2? I found it at version 3.0.2.

and, Can temple add some more tools such as:
 1. printf-as3?
  2. zipfile utils?

Mark Knol

unread,
Oct 23, 2012, 3:39:27 AM10/23/12
to temple...@googlegroups.com
J.Wang,

There are some more other ways of logging objects. You can use dump() instead of the older TraceUtils.traceObject. I believe these are globally available inside the utils module.

// dump(object:Object, depth:uint = 3, duplicates:Boolean = true, constants:Boolean = false, namespaces:Boolean = false, methods:Boolean = false, dates:Boolean = false):String
trace(dump(myObject));

You can also use objectToString which creates a nice readable string of an object.

// objectToString(object:*, props:Vector.<String> = null, notEmpty:Boolean = false):String
trace(objectToString(myObject, Vector.<String>["name", "id"]));

I'm not sure but I guess it's been deprecated to force to use the Log class. This class gives more control if a trace should be send or not. This is useful to quickly setup production-ready applications (you don't want to send debug info in your final app). The messages will also be send to Yalog using a local connection. You can use the ready for use yalala which basically is an ready to use (extended) version of Yalog.

These methods metioned above are very specific. That said, you can use the global log function which does the 'trace' for you.

// log (message, object, depth);
log("myObject", myObject, 4);


.. Basically the log is a friendly way to send a message to the Log class. But of course you can call the Log functions yourself:

Log.addEventListener(handleLogEvent);    // handle events locally
Log.showTrace(false);    // don't output log messages as traces

Log.debug("This is a debug message", this);
Log.error("This is an error message", this);
Log.info("This is an info message", this);


If you extend CoreObject (or CoreSprite, CoreMovieClip CoreBitmap etc..), you have even more quick access to these functions, because its build-in.

this.logInfo("This is an info message");
this.logDebug("This is an debug message");
this.logError("This is an error message");
this.logStatus("This is an status message");


As you can see, there are a lot of ways to give you debug information.


You also noted to add printf-as3. I haven't use this library, but you could take a look at StringUtils.replaceVars() inside the utils module.

trace(StringUtils.replaceVars("hello, my name is {name}", {name:'Mark'}));
// output: hello, my name is Mark


Hope that helps.

Thijs | MediaMonks

unread,
Oct 23, 2012, 4:10:36 AM10/23/12
to temple...@googlegroups.com
The traceObject method has been replaced with the new 'dump' method. The dump() method is the same as the old traceObject method, but with some improvements:

- the dump() method does not do a trace, but returns the object tree as string to you can trace is yourself: trace(dump(object));

(Or you can use one of the other methods Mark mentioned.)

- the dump() method is a top-level method so you don't need to import.

- the dump() method has improvement for handing namespaces, constants, methods and dates.

Regards, Thijs
Reply all
Reply to author
Forward
0 new messages