10 tips and tricks using ThunderBolt AS3
June 15th, 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:
-
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:
log level example ( Download code )
-
import org.osflash.thunderbolt.Logger;
-
-
//
-
// some log objects
-
var myNumber: int = 5;
-
var myString: String = "Lorem ipsum";
-
-
// INFO log level
-
Logger.info ("Just an info message");
-
//
-
// DEBUG log level
-
Logger.debug ("A debug log ", myString);
-
//
-
// WARN log level
-
Logger.warn ("A warn message", myNumber);
-
//
-
// ERROR log level
-
Logger.error ("An error log ", myString);
Screen shot using Firebug:
Screen shot using ThunderBolt AS3 Console:
-
-
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:Example for logging few objects at once ( Download code )
-
import org.osflash.thunderbolt.Logger;
-
-
//
-
// some log objects
-
var myNumber: int = 5;
-
var myString: String = "Lorem ipsum";
-
-
var myObject: Object = { exampleArray: ["firstValue", "secondValue"],
-
y: 10,
-
exampleString: "Hello",
-
nestedObject: { x: 100,
-
y: 200}
-
};
-
-
// Logging an object with nested items
-
Logger.info ("Logging an object with nested items ", myObject);
-
//
-
// Logging more objects at once
-
Logger.info ("Logging more objects at once ", myString, myNumber, myObject);
Screen shot using Firebug:
Screen shot using ThunderBolt AS3 Console:
-
-
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:Example for using Flex logging API ( Download code )
-
import mx.logging.Log;
-
import org.osflash.thunderbolt.ThunderBoltTarget;
-
-
// init ThunderBoltTarget
-
_target = new ThunderBoltTarget();
-
-
/*
-
You can disable the time, level or category as well
-
_target.includeTime = false;
-
_target.includeLevel = false;
-
_target.includeCategory = false;
-
*/
-
-
_target.filters = ["de.websector.playground.ThunderBoltTargetExample"];
-
Log.addTarget(_target);
-
-
// start logging
-
Log.getLogger("de.websector.playground.ThunderBoltTargetExample").info("Just an info message.");
Screen shot using Firebug:
Screen shot using ThunderBolt AS3 Console:
-
-
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;
-
-
-
Show a memory snapshot
Make a memory snapshot whenever you want:
-
Logger.memorySnapshot();
-
-
-
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;
-
-
-
Using the new ThunderBolt AS3
v.2.1betav.2.0 and its ConsoleThe new version of ThunderBolt AS3 (
v.2.1betav.2.0) detects either Firebug is installed or not. If not, then it uses the well knowntrace()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
-
-
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.1betav.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:trace() example for using ThunderBolt AS3 Console ( Download code )
-
//
-
// tracing an info log level
-
trace ("info Here is an info message to display using ThunderBolt AS3 Console");
-
//
-
// tracing an error log level
-
var myString: String = "hello console";
-
trace ("error Here is an error message" + myString);
-
//
-
// tracing an debug log level
-
trace ("debug Here is a debug message" + myString);
-
//
-
// tracing a warn log level
-
trace ("warn Here is a warn message");
Screen shot using ThunderBolt AS3 Console:
-
-
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”
-
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!


June 16th, 2008 at 12:29 pm
[...] Du kan læse meget mere om ThunderBolt her: 10 tips and tricks using ThunderBolt AS3 [...]
June 22nd, 2008 at 4:14 am
[...] ????????????????10???? 10 tips and tricks using ThunderBolt AS3 [...]
October 23rd, 2008 at 1:00 pm
[...] There is an AIR app version too, although it doesn’t sound very Windows friendly… for more info check this out [...]
December 2nd, 2008 at 10:45 am
I’ve been using your tool for a while now (ooeer!) and I love it … for someone who uses their laptop all the time for developing on the train, having your logging output right there in the browser is invaluable. Something to consider for the future, how about a Flex tool for overlaying visual guides on-screen … that would be sweet. Also, it would be great if Firebug was dockable to the side of the browser in Portrait mode … question for them I guess. Anyway, thanks for the great TOOL!
December 12th, 2008 at 6:09 pm
Moin Jens,
thank you for Thunderbolt! I had one little issue with it: the automatic detection of Firefox was not working (Win XP, FF3.0.4, FlashPlayer 10) so I’ve added to my code:
Logger.console = false; // Firefox?
try {
Logger.error(“”); // maybe not
} catch (error:Error) {
Logger.console = true;
}
Cheers,
Stefan
October 12th, 2009 at 12:14 am
[...] both the Flash IDE and in Firefox. For a quick introduction to Thunderbolt, check out the Article 10 tips and tricks using ThunderBolt AS3, by Thunderbolt’s author Jens [...]