|
Instructions
IntroductionA guide to using FlashLogger for ActionScript and JavaScript programmers. NOTEThis page is currently out-of-date. The examples here will still work, but there is much more available. Check out the HOWTO.txt file for a few more details. More documentation coming soon! DetailsACTIONSCRIPT SETUP AND USAGE:Copy the com folder (and it's sub folders) to your project folder. In your ActionScript code you can create an instance of the logs like so: var log:Log = new Log("instance_key");Of course, you're more apt to have your log be a private member of your class, so your code might look more like: package my.package
{
import flash.display.MovieClip;
import com.thomporter.utils.Log;
class MyClass extends MovieClip
{
private var log:Log;
public function MyClass
{
log = new Log("my.package.MyClass");
}
}
}By default, logs are off, so while you're developing, you'll want to add: log.on(); You can also do this in the HTML with a little JavaScript, so you can just delete the one line of JS from your HTML source instead of worrying about it being buried in the source of your ActionScript classes. Do this like so: <script type="text/javascript">
$FL("<instance_key>").on();
</script>Now you can call the log method of your instance of the Log class like such: log.log("hello world");You can pass 2 parameters to the log function, both will be passed on to the JavaScript API for display in FireBug's console: log.log("me:", this);Notice the instance key I choose for the MyClass log instance? In the future, you will be able to turn logs on and off using a selection path based on the instance key. So you could do this in the JavaScript console to turn on an entire package's logging: $FL("my.package.*");While this feature isn't available yet, it is planned, and I suggest using the fully quallified package.classname of your class as the instance key. JAVASCRIPT SETUP:Simply place this script tag in the <head> of your HTML document: <script src"/path/to/flashLogger.js"></script> Replace "/path/to/" with the path to where you upload flashLogger.js and you're all set! JAVASCRIPT USAGE:FlashLogger isn't just for ActionScript. Turns out the JavaScript API is a pretty handy tool for JavaScript programmers too, especially with complex projects where it is nice to "section off" debugging statements. The JavaScript API allows you to easily turn sections on and off, so you can see just what you need to see. Here's an example of how to use the JavaScript API: <script type="text/javascript">
// create an instance of the JavaScript FlashLogger
var log = $FL("my_instance_key");
// Now the log is ready, but it is off. We can force it on via code like so:
log.on();
// Alternatively, we could just turn it on when we create it:
var log = $FL("my_instance_key").on();
// Now you log just like so:
log.log("hello world");
// You can pass 2 parameters as well:
log.log("my logging instance:", log);
// The on(), off() and log() methods all return the logger, so you can force
logs to show like so:
log.on().log("this will always show up in the log.").off();
</script>It's good to turn your logs on by default while developing, but turn them off when you're done. If you ever need to turn them on, you can do so from the JavaScript console like so: $FL("my_instance_key").on();
|