10 tips and tricks using ThunderBolt AS3

Posted on June 15, 2008

Almost one year ago I started to develop a small extension called ThunderBolt AS3 for logging ActionScript 3 applications using Firebug as simple as possible. Today its nice to see that the community uses and supports this extension as well.

For all those who not familiar with it: ThunderBolt AS3 is a lightweight logger extension for any ActionScript 3 applications based on Flash CS3, Flex or Adobe AIR using Firebug or its own ThunderBolt AS3 Console.

Here are some tips and tricks using ThunderBolt AS3:

1) Using different log levels

ThunderBolt AS3 supports different log levels, which based on the supported levels by Firebug, such as "info", "warn", "error" or "debug". It's pretty simple to use it:

 1 import org.osflash.thunderbolt.Logger;
 2 
 3 //
 4 // some log objects
 5 var myNumber: int = 5;
 6 var myString: String = "Lorem ipsum";
 7 
 8 // INFO log level
 9 Logger.info ("Just an info message");
10 //
11 // DEBUG log level
12 Logger.debug ("A debug log ", myString);
13 //
14 // WARN log level
15 Logger.warn ("A warn message", myNumber);
16 //
17 // ERROR log level
18 Logger.error ("An error log ", myString);

Screen shot using Firebug

Screen shot using ThunderBolt AS3 Console

2) Logging one or more objects at once

ThunderBolt AS3 logs more than one objects at once. It could be primitive types (int, uint, Number, Boolean, ...) or more complex data such as an instance of any classes or nested objects. Here an example:

 1 import org.osflash.thunderbolt.Logger;
 2 
 3 //
 4 // some log objects
 5 var myNumber: int = 5;
 6 var myString: String = "Lorem ipsum";
 7 
 8 var myObject: Object = { exampleArray: ["firstValue", "secondValue"],
 9                          y: 10,
10                          exampleString: "Hello",
11                          nestedObject: {    x: 100,
12                                          y: 200}
13                      };
14 
15 // Logging an object with nested items
16 Logger.info ("Logging an object with nested items ", myObject);
17 //
18 // Logging more objects at once
19 Logger.info ("Logging more objects at once ", myString, myNumber, myObject);

Screen shot using Firebug

Screen shot using ThunderBolt AS3 Console

3) Using the Flex Logging API

ThunderBolt AS3 supports the Flex Logging API using its own log target called ThunderBoltTarget. To use it you will need to use and import the ThunderBoltTarget.as as well:

 1 import mx.logging.Log;
 2 import org.osflash.thunderbolt.ThunderBoltTarget;
 3 
 4 // init ThunderBoltTarget
 5 _target = new ThunderBoltTarget();
 6 
 7 /*
 8  You can disable the time, level or category as well
 9  _target.includeTime = false;
10  _target.includeLevel = false;
11  _target.includeCategory = false;
12 */
13 
14 _target.filters = ["de.websector.playground.ThunderBoltTargetExample"];
15 Log.addTarget(_target);
16 
17 // start logging
18 Log.getLogger("de.websector.playground.ThunderBoltTargetExample").info("Just an info message.");

Screen shot using Firebug

Screen shot using ThunderBolt AS3 Console

4) Stop and hide logging

To release your project you might to disable all logging data. Then put the following line into your code.

Logger.hide = true;

5) Show a memory snapshot

Make a memory snapshot whenever you want:

Logger.memorySnapshot();

6) Show or hide a time stamp

Lets make a time stamp. The default value is "true". To hide the time stamp use this:

Logger.includeTime = false;

7) Using the new ThunderBolt AS3 v.2.1beta v.2.0 and its Console

The new version of ThunderBolt AS3 (v.2.1beta v.2.0) detects either Firebug is installed or not. If not, then it uses the well known trace() method to log all data into "flashlog.txt". You can enforce this process using:

Logger.console = true;

To show all information in a well defined structure I'd recommend to use the new ThunderBolt AS3 Console. It's a handy tool to log any AIR application as well ;-)

8) Using the ThunderBolt AS3 Console for logging ActionScript 1 or 2 projects

As described above ThunderBolt AS3 Console follows a simple principle: It reads just all information logged by the ThunderBolt AS3 Logger (v.2.1beta v.2.0) into "flashlog.txt" and shows it in a hierarchal order based on different log levels. That means you can use ThunderBolt AS3 Console for logging any AS 1 or 2 projects too ;-) . Just call a trace() method as follows. Note the prefixes named "info", "error", "warn" or "debug" followed by a whitespace at the beginning:

 1 //
 2 // tracing an info log level
 3 trace ("info Here is an info message to display using ThunderBolt AS3 Console");
 4 //
 5 // tracing an error log level
 6 var myString: String = "hello console";
 7 trace ("error Here is an error message" + myString);
 8 //
 9 // tracing an debug log level
10 trace ("debug Here is a debug message" + myString);
11 //
12 // tracing a warn log level
13 trace ("warn Here is a warn message");

Screen shot using ThunderBolt AS3 Console

9) Any issues with the Flash Player security sandbox using Firebug?

If you have any security issues with the Flash Player security sandbox using ThunderBolt AS3 and Firebug set within your HTML template the value of the parameter named "allowScriptAccess" to "always". For more information check Adobes Flex 3 Help: "About ExternalInterface API security in Flex"

10) Issues using ThunderBolt AS3 Console on Windows?

What a pretty sh...y thing: The ThunderBolt AS3 Console is currently available for OS X only. There are some issues using an opened AIR app and "flashlog.txt" at the same time on Windows. Check out this entry at Adobes AIR forum for more information. Hoping that Adobe will fix this issue in the future. So long, sorry for all the Windows user out there :-( . BTW: Feel free to post here your request to Adobes AIR team as well ;-)

Open source!

ThunderBolt AS3 and its console is open source! Grab the source, change and adapt it. Or do whatever you want ;-)

Happy logging!

Any feedback?

comments powered by Disqus