21 Apr 2009

Logging to firebug from flex 3

It’s been awhile since I’ve posted, which wasn’t what I had in mind but nevermind.

I’ve been working on the next version of the Videojuicer Player and as part of the core I’ve implemented a custom logging engine which records and outputs to the Flex Builder console through trace. I wanted to expand the logging functionality so that I could view the console output through the Firebug console, since I’m using Firefox when I’m testing the application it makes more sense.

I decided to create and share a simple class for accessing the Firebug console from Flex 3 or Actionscript 3. After creating an instance of the class, you can call the different methods to send a message to the Firebug console. The code utilises the ExternalInterface class from the Flex framework to call the javascript functions and because of this the page hosting the Flex application needs to include the scripting="always" parameter on the embed / object tag.

The code is hopefully self explanatory, and isn’t really that complicated. You can use the class quite simply:

Use the ‘raw’ link below the snippet to download the source from GitHub.

Gist

The code has been tested and works perfectly in Flex 3.3 + 3.2 with Firefox 3.1b3 and Firebug 1.4, all running on OS X 10.5. It should work fine with other versions of Flex 3, Firefox and Firebug without any modifications.