26 February 2008

Firebug’s Console Log, Flash debugging made easy

I have to admit, debugging in Flash has always been a painful thing. There’s nothing more stressful when everything works fine in the IDE, but completely craps out once pushed to the site, and you’ve got to figure out the problem right freakin’ now when the most you have to go on is “um, the Flash doesn’t work.”

Enter Console Log. For those of you who don’t have Firebug, get it. Now you can trace out to the Firebug console log from your .swf.

It’s as simple as two lines of code:

First, import the package declaration:

import flash.external.ExternalInterface;

Next, call to the log whenever you want to trace something out

ExternalInterface.call( "console.log" , "Hey! I'm tracing from Flash!");

Yes. It’s that simple. You can even add variables and other data to the trace. Just treat the argument as any other string:

ExternalInterface.call( "console.log" , "My variable is" + myVar );

This is even more useful when you can’t actually view the site. We recently had to debug an issue that was behind a client’s firewall. Rather than guessing back and forth, we were able to deliver a new .swf with a bunch of calls to the console, and solved the problem in a matter of minutes, as opposed to hours of guesswork.

Try it for yourself. You’ll appreciate how useful it is.

posted by David Lowe-Rogstad

thinking about… AS3, Flash, Productivity

8 Comments…

  1. Nate Miller said…

    Simple, and elegant. Thank you, sir!

    5:37 pm / March 14th, 2008

  2. KnuckIfYouBuck said…

    Perfect, this is exactly what I was looking for.

    7:16 pm / October 27th, 2008

  3. Alo? said…

    Is there a way to see the traces from Flash in the Net tab with the other requests?

    8:04 pm / October 27th, 2008

  4. Alo,

    As far as I know, there isn’t a way to write to the Net tab. That tab is logging all network events and a trace on the client side .swf shouldn’t be wrapped into that sort of information.

    If you could give us a better idea of what you are trying to do, or why you’d want to do that, we can see if there’s a solution.

    9:58 pm / October 27th, 2008

  5. erixtekila said…

    Simple but slow, limited to 40 kb buffer and reinventing the wheel :
    http://code.google.com/p/flash-thunderbolt/

    HTH

    4:41 pm / December 17th, 2008

  6. Glenn Barres said…

    Who cares if it is reinventing the wheel. At least with this you don;t need to install or add some new component.

    If everyone thought that since a wheel has already been made, no need to rethink it, we would not have computers that keep getting faster, cars that get better mileage, or different flavored pizza’s.

    Think outside the box erixtekila

    8:27 am / April 30th, 2009

  7. Joshua said…

    If you use the latest version of firebug be aware you need to ping the console directly from javascript before your SWF’s can do so…

    http://code.google.com/p/fbug/issues/detail?id=1494

    9:40 am / May 12th, 2009

  8. hamish said…

    Following up from Joshua, you must have a script tag in your page even if you don’t have any javascript or it does not work

    3:11 am / October 1st, 2009

  9. [...] s konzolí podrobně Firebug a Flash Oficiální [...]

    3:49 pm / January 4th, 2010

Have a comment?