doBreak - very useful for debugging code from .as files. Since breakpoints for .as files are not saved between executions, you have to manually set them each time you want to break inside a .as file. Instead, add:
function doBreak(msg)
{
trace("doBreak: " + msg);
return;
}
to your first frame. (Always on a seperate Actions layer!!) Add a breakpoint at the trace statement. Then call doBreak whereever in your .as files, run in debug mode, and the program will break inside the doBreak. Then press the “step out” button and you’re at the right place for debugging. Props to “Alan Prather” aprather@andrew.cmu.edu for the tip.
A problem I ran into was debugging a SWF when it was out of the IDE. trace() isn’t an option, NetDebug.trace() works, but is a pain to use because you have to have the Net-Debugger open at all times. I wanted something that was simple, light-weight, and doesn’t require use of an external program or SWF. I created the debug class to solve this problem. It’s basically a textfield that sits on-top of all your content in your movie. To trace to the textfield simply call debug.trace(), you can set the color of the text in the textfield by calling debug.setColor().
Sometimes you need to dig deeper and see what your object actually contains, but you might not know what type it is, you might not have the source code to be able to create a nice toString() method for it. Here’s various ways and means of inspecting your objects insides.
for(var element in myObject) { trace(element + " : " + myObject[element]); }
see this blog entry
I created a static class to be able to recursivly trace complex data (Array of Objects). I’m pretty sure there’s others out there, but here’s mine anyway.
class com.muzakdeezign.utils.Dump { static function output(o, indent) { var retObj = ""; var tab:String = (indent == undefined) ? " " : indent+" "; // if (o instanceof Function) { retObj = o; } else if (o instanceof Date) { retObj = o; } else if (o instanceof XML) { retObj = o; } else if (o instanceof Array) { retObj += "[object Array]"; for (var i = 0; i<o.length; i++) { retObj += "\n"+tab+"["+i+"]: "+output(o[i], tab); } } else if (o instanceof Object) { retObj += "[object Object]"; for (var prop in o) { retObj += "\n"+tab+prop+": "+output(o[prop], tab); } } else { retObj = o; } return retObj; } }
Usage example:
import com.muzakdeezign.utils.Dump; // var _xml:XML = new XML("<main></main>"); _xml.firstChild.appendChild(new XML("<childNode />")); // var complex_data:Array = [{label:"Hello", data:"World"}, {label:"Hello", data:"World"}, function () { }, new Date(), _xml]; // trace(Dump.output(complex_data));
Will display the following in the output window:
[object Array]
[0]: [object Object]
label: Hello
data: World
[1]: [object Object]
label: Hello
data: World
[2]: [type Function]
[3]: Fri Aug 19 16:55:36 GMT+0200 2005
[4]: <main><childNode /></main>