Tr.ace() 2.0: An Excellent AS3 Debugging Utility

Tr.ace() 2.0: An Excellent AS3 Debugging Utility

Tutorial Details
  • Platform: Flash (Flash Player 9+)
  • Software Supported: Any Flash Editor (optimised for FlashDevelop)

Last year, we released Tr.ace(), an open source debugging tool for Flash that expanded on the built-in trace() function. Now, Tr.ace() v2.0 introduces several new features including the much requested “textfield console” to help you squash those bugs once and for all!


New to Tr.ace()?

Tr.ace() was released nearly a year ago as an Exclusive Freebie on Activetuts+ and is an open source debugging utility for Flash that allowed you to restrict the traces shown within your application to particular users or classes or even both. You could also add linebreaks, timestamps and trace nested arrays and objects neatly with one line of code!

Let’s take a look at what’s changed since Tr.ace() was first released…


By Popular Demand: Tr.ace() Console

The Tr.ace() library now features a class named TrConsole which provides you with a basic console within your SWF through which you can view all your Tr.ace() traces! Check out the demo below to see it in action:

You can clear the console, copy the output to the clipboard and save the output to a text file. You can also minimize the console to reduce the space taken up on screen as well as move it around the screen by simply dragging it. It’s also fully resizable!

To take advantage of this feature you only need two lines of code:

// create the TrConsole instance and add it to the stage
var console:TRConsole = new TrConsole();
addChild(console);

And that’s it – easy!

There are also a few extra options for you to tailor the colours of the console and whether autoscroll is enabled or not. Check out the documentation and example files for more info.


Optional Username and Class Parameters

When Tr.ace() was intially released the username and class parameters were required for all trace calls whether you wanted to use them or not. You’ll be happy to know that they are now optional!

This does reduce some of the functionality of the library but if you’re just wanting to see your traces via the console then you’re able to, without the bloat of the rest of the library.

With parameters:

Tr.ace("with parameters", TrUsers.MSFX, ClassName);

Without parameters:

Tr.ace("without parameters!");

This will hopefully make the library more accessible and less “verbose” for tracers everywhere.


Clear, Copy and Save Your Traces

Via the console featured above you can clear, copy to clipboard, and save the current trace log.

For those who aren’t using the console you can also achieve these via calls to the Tr class as shown below:

// to clear the trace log
Tr.clearLog();

// to copy to the clipboard
Tr.copyLogToClipboard();

// to save the log as a text file with timestamp
Tr.saveLog();

The clipboard functionality must be triggered via a user interaction, as detailed here.


Downloading Tr.ace()

Tr.ace() is an open source library that is available to download here at Activetuts+ in ZIP format and is also available as a public repository on my GitHub, for those a little more nerdy or who wish to fork and/or contribute towards the Tr.ace() library.

The library is AS3 only and has two separate repositories developed for both Flash Player 9 and Flash Player 10+

To use the Tr.ace() library you must download one of the above source packages and copy and paste the ‘uk’ directory, located within the ‘src’ directory, into your global classpath directory. You’re then all set to go!


Documentation for Tr.ace()

Within the download package you’ll find a ‘docs’ directory; open the index.html file to view the ASDocs-generated documentation for Tr.ace(). You can also find the documentation online: http://docs.msfx.co.uk/as3/trace/.


Happy Tracing!

So, that’s it really. If you have any questions or suggestions for the library feel free to get in touch in the comments.

Happy tracing!

Matt Stuttard Parker is MSFX on Activeden
  • Jason

    Just a couple of feature suggestions (I haven’t tried Tr.ace, so these are just from looking at the docs). First, I’m a little confused to why Tr.aceArray is a separate function. Why not just merge it with Tr.ace? Secondly, it would be cool to add colors to the traces done in a TextField. This could be quite useful.

  • http://www.gemfruit.com Porter

    This looks pretty cool. I’m always looking to cut down on debugging time, as I spend way too much time doing so, and this looks like it could help. I’ll check it out tonight or tomorrow when I have some time. Also, the color suggestion above sounds like a great idea. Separating types of traces into color could be a extremely beneficial.

  • http://msfx.co.uk MSFX
    Author

    @Jason,

    1) It was an after thought and was easier to add that way

    2) Being able to colour particular traces would be cool, are you thinking on a two tone basis from line to line or for each individual trace specifying a colour – not quite sure why you’d want the latter…

    @Porter

    Thanks!

    • http://pierrechamberlain.ca/blog Pierre Chamberlain

      I think if a TextColor feature is to be implemented, it should be “user” specific, or perhaps even class specific. Not too sure what TrUsers store in the static variables, but a special Class ValueObject type just to store the username and text-color for that particular user might be a nice feature. If a user needs several colors, he could just append more static variables to TrUsers, such as:

      TrUser.TUTPLUS_WARN = new TrUser(“TUTPLUS_WARN”, 0xee8800);
      TrUser.TUTPLUS_ERROR = new TrUser(“TUTPLUS_ERROR”, 0xff0000);

      Maybe this ValueObject class (ex: TrUser) should be part of the library, and could be extended depending on developer needs?

    • http://michaeljameswilliams.com/ Michael James Williams

      Didn’t you implement colours in v1, for FlashDevelop? I can’t remember how that worked…

      • http://msfx.co.uk MSFX
        Author

        Yeah that’s based on the FlashDevelop console’s internal workings by appending “x:” at the start of the trace where x is 0-5.

  • Konstantin

    It’s not very comfy to use Tr.ace with FD because of its advanced auto-completion system. You’d have to always press ESC after you type Tr to cancel a prompt window because FD will definitely prompt something else.
    Well, actually, I can’t imagine the situation I would need something like that at all. Any normal IDE has it’s own remove debugger which can connect to the debug version of FP and catch its traces

    • http://msfx.co.uk MSFX
      Author

      I use it with FD all the time and never have any issues…?

      Interesting, how would you for instance connect FD to the debug player within Chrome? That would be useful to know…

  • Sage

    @MSFX: I am not quite sure what you mean but there is no problem in connecting FD to Chrome Flash Player. They only thing you need to do is to turn off default Flash Player by accessing about:pluings and install Flash Player Debugger for Chrome. That’s all.

  • http://twitter.com/codedev coolcoder

    How do you get this to work in a Flex application?

  • newbie

    Thanks. Your library is very useful for me. I’m new in Flash, so I have some question: Why do you have to override mouseEventHandler to provide clear, clipboard, and save feature? And, do you plan to release next version of this lib in future?