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

  • Swear (PIC)

    Imperial Stormtrooper is sworn in for the American army in Iraq.

  • Linux Media Center Edition

    Controls everything from your TV to your security system using anything from your cell phone to a Wii remote.

  • 7 Visions Of Social Networking’s Future: Is This Web 3.0?

    Considering that there are now kids in college who don’t remember a time before the Internet, we can only imagine what will be possible in just a few short years.Here is a list of scenarios and technologies that will shape the Internet’s future. Some are already available and a few we’d like to look forward to in the near future:

  • Samba Team Releases Samba 3.2

    The Samba Team is proud to announce the release of Samba 3.2, a major new release of the award-winning Free Software file and print server suite for Microsoft Windows clients.

  • Eee Monitor shots reveal Linux's $500 iMac rival

    ASUS' Eee Monitor today has been captured in official photos that confirm the system to be the company's direct answer to the iMac. The all-in-one computer confirms earlier teaser photos and reveals a cross between Apple's Cinema Displays and the iMac, but with two big differences: the use of Linux and just a $500 price tag.

  • Sales Guy vs. Web Dude

    The Website is Down - This is super funny.

  • PC Magazine's 12 Favorite Music Sites

    These days, a good radio station is hard to come by and CDs are $20 a pop. So, what's a music lover to do? Turn to the Internet, of course, where you can find music-streaming services that are not only free and legal (like all radio) but customizable.

  • Lego Star Wars Clone Trooper Army Fights Autism

    What are 35,310 Lego Star Wars Clone Troopers mini-figs doing together, apart from planning a planet invasion after breaking out of the giant Lego storage cathedrals? Raising awareness and funds for autism, that's what.

  • 10 Useful Apps To Reduce Your Dependency On Google

    They are worth being familiar with so that you can avoid a crisis situation when you cannot access a Google product for some reason.

  • A cross between a motorcycle, a Segway and 'Star Wars'

    Meet the Uno. The Uno's custom hoops aren't front and rear like a motorcycle's, but side by side and inches apart under the rider, rising and falling independently over the road as he leans the gyroscope-stabilized machine through effortless turns.

Subscribe

Who Am I?

No Sweat Apparel.com