com.esiteful.debug.localTrace
Posted by stephen on October 16th, 2008Since the ability to post to firebug’s console has been available, I’ve loved taking advantage of it. I created this debug function in order to trace errors to the Flash console with trace(myMsg), and to the Firebug console with ExternalInterface.call(”console.log”, myMsg). Here are the parameters localTrace accepts and their defaults:
localTrace(localTrace(traceMsg, debugMode=1, debugLvl=1, jsAlert=false);
- traceMsg is the message you want to send to the console.
- debugMode is the debug status of the referencing object.
- debugLvl is the priority of the error message.
- jsAlert tells the function whether or not to show the message as a javascript alert.
(useful if your browser does not have a console)
traceMsg is the only required parameter, meaning you can use this function by just calling localTrace(”test message”).
Example Usage
In the referencing timeline actions or class, add an import line for the function.
import com.esiteful.debug.localTrace;
Create a variable called debugMode and set it to something between 1-5 (you can use however many numbers you’d like, but I generally don’t use more than 5).
var debugMode:int = 3;
Now make a call to localTrace(). I usually have a trace at the top of each of my functions so I know when they’re fired, but I obviously don’t always want these to show, so I give them a debug level or 2 (or higher, depending on their repetitivity).
I give error message that are caught in a try/catch a priority of 1. So, here’s a sample of debugging a simple function.
import com.esiteful.localTrace;
var debugMode=3;
function awesomeLogic(logicString){
try{
localTrace("[awesomeLogic("+logicString+")]“, debugMode, 2);
//put your logic here
}catch(err:Error){
localTrace(”Error at awesomeLogic\n”+err, debugMode, 1);
}
}
I couldn’t get the above quotes to show up correctly for the life of me…guess it’s about time to look for a good code container for these examples…
If this function is part of a class, I would change the messages include that (e.g. “className.awesomeLogic”).
There you have it! Of course, all suggestions on debugging are welcome.
Download com.esiteful.debug.localTrace.
Recent Comments