A Simple in-swf debugger

When developing a Flash app for the web sometimes it can be painful seeing what’s going on as you can’t trace things in the browser - not that I’m aware of anyway.

If you use FireBug in FireFox when you are developing you can set up a function in javascript that allows you to see what you a tracing using this same method but outputting it to the javascript debugger and/to FireBug using:


function debug(aMsg) {
setTimeout(function() { throw new Error("[debug] ” + aMsg); }, 0);
}

I didn’t write this I can’t remember where I found it probably at on here somewhere. Also you don’t need to use FireBug but if makes it a lot easier.

So you call this function from flash using using either an External Interface call or using getURL for older versions of the Flash player. If you write the function right you can include a trace as well so you can follow the same process while working in Flash itself. If you want to be really clever you can output the things you are tracing to a TextArea within Flash as well. Here is idea of what the function might look like:


//str is what you want to trace
function debugging(str){
//trace the str in Flash
trace(str);
if (_root.debugger.showText == 1) {
//this is the putting str in the TextArea
_root.debugger.alert.text = str+'
‘+_root.debugger.alert.text;
}
//this calls the debug function in javascript
getURL(’javascript:debug(”‘+this.sender_name+’ : ‘+str+’”)’);
}

In some of the apps I have built using this you can also turn the debugger on and off in javascript this makes the whole thing quite complete and make the developing process a lot easier.

This only works in FireFox but you can always add a switch to get an alert in Explorer.

If you want something I but more sophisticated to your debugging you need to use Ash Atkins Debug Console class. I do use this but I find the first idea more useful generally.

Comments

Leave a Reply

Stuff I Dugg

  • Drivable Star Wars Landspeeder Kicks Ass

  • One Less Windows User

    After nearly five years, I needed to update my personal computer. My old Dell Inspiron has long since been rendered quaint by advances in processor speed and hard drive capacity. Rather than buy a new machine running Windows Vista or take the Mac plunge, I decided to walk the open source walk.

  • 20 Tech Habits to Improve Your Life

    A few new habits can make the difference between staying on task, finding what you need, and getting things done--or having a tech meltdown.

  • Space Cube - The World's Smallest Linux PC

    Meet the Space Cube — the world's smallest fully functional PC. Primarily designed for use in space, it somehow manages to cram a working PC with USB ports, card readers, audio outputs and proprietary interfaces into a tiny cube chassis measuring just two inches square. It runs a basic Linux front-end.

  • How Simple Web Design Helps Your Business

    It’s crucial to have simple web designs to allow the user to quickly find the information they need, especially if you are selling a product. If the page is cluttered with useless text, widgets or unrelated products, the site becomes meaningless.

  • 24 Core, 48GB Linux Render Cluster built inside IKEA Cabinet

    This amazing Linux Cluster consists of 6 Intel Core 2 Quad(2.4GHZ) Processors, 48GB of RAM spread across 6 GIGABYTE GA-G33M-DS2R Micro ATX motherboards and put inside an IKEA Helmer cabinet, WHY YOU ASK? 3D computer rendering is very CPU intensive and the best way so speed up slow render problems, are usually to distribute them on to more computers

  • 25 killer Linux apps

    The very best software for your Linux machine.

  • Lego Star Wars Olympics 2008 [Flickr Photo Set]

    Beijing 2008 Olympic Games

  • Leaked Document Shows Verizon's Anti-iPhone Propaganda

    Verizon's tactics to combat the Jesusphone 3G now include briefing its employees about the iPhone's failings, so they can answer customer questions about why it doesn't carry the device.

  • 10 Good UNIX Usage Habits

    Adopt 10 good habits that improve your UNIX® command line efficiency -- and break away from bad usage patterns in the process. This article takes you step-by-step through several good, but too often neglected, techniques for command-line operations.

Subscribe

Who Am I?

No Sweat Apparel.com