Debugging Tricks

FlexBuilder 3 Beta 2 no longer makes both release and debug versions on every build, in order to speed up build times. This means that the debug version is no longer suffixed with -debug and it appears more than one of you used that to turn on debugging functionality w/o changing your code.
Also, a few folks have asked for a single line of code that could be pasted verbatim into function bodies that would report the name of the function, and a few others have wondered if there is a way to get the name of the calling function.
Assuming you are using a debugger player, the source code at this link demonstrates how to do each of these things. See setDebugFlag(), getFunctionName() and getCallingFunctionName().
Download file

private function setDebugFlag():void
{
var e:Error = new Error();
var s:String = e.getStackTrace();
// trace(s);
var i:int = s.indexOf("setDebugFlag");
if (s.charAt(i + 14) == '[')
debugMode = true;
}
[Bindable]
public var debugMode:Boolean = false;
private function getFunctionName(e:Error):String
{
var s:String = e.getStackTrace();
var i:int = s.indexOf("at ");
var j:int = s.indexOf("()");
return s.substring(i + 3, j);
}
private function getCallingFunctionName(e:Error):String
{
var s:String = e.getStackTrace();
// trace(s);
var i:int = s.indexOf("at ");
i = s.indexOf("at ", i + 3);
if (i == -1)
return "caller unknown";
var j:int = s.indexOf("()", i + 3);
return s.substring(i + 3, j);
}

where the latter two functions are can be used like this:

private function doSomething():void
{
trace(getFunctionName(new Error()));
doit();
}
private function doSomethingElse():void
{
trace(getFunctionName(new Error()));
doit();
}
private function doit():void
{
trace(getFunctionName(new Error()));
trace("   called by", getCallingFunctionName(new Error()));
}

Usual caveats apply, and the numbers and strings might have to be adjusted for different languages.