Fresh Thoughts Blog

Setting up Flash CS4 to log trace messages to a file

Written by Cappy Popp | Dec 8, 2008

This is a very handy feature, especially if you have to write your code in Actionscript 2 for which the Flash CS4 debugger is terrible, terrible, terrible. Trace messages are great but when your Flash .swf is running in a browser, and needs to (for instance if it is running on a Facebook application and needs to interact with Facebook real-time) but without using a tool - there are a few - or a custom Flash listener how can you see your trace messages?

Here's how to log them to a file. Note that these instructions are different from what Adobe recommended for Flash CS3/ Flash Player 9. They have changed the rules a bit. Here's how to get this working for Adobe Flash CS4 and the latest Flash Player (version 10.0.12.36 as of this post date.)

Uninstall your current Flash players

Go here and get Adobe's Flash Player uninstaller. Do not try to uninstall your Flash players any other way unless you know exactly what you are doing. You will just screw things up. Close your browsers and run the uninstaller you downloaded.

Download and install the latest Debug Flash Players

Go here to get them. Close all of your browser windows first, then install the plugin version (for FF and plugin-based browsers) and the the ActiveX version for IE. This assumes you are running Windows. Follow instructions in previous link if you are running OSX or Linux.

Create the mm.cfg file

Again, this assumes you are running Windows. Open Explorer and go to the C:\Documents and Settings\[your username] directory. If you don't have this directory check what your HOMEPATH environment variable is set to and browse to that directory instead. Create a text file in this directory named mm.cfg. Paste the following 2 lines of text into the file:

ErrorReportingEnable=1
TraceOutputFileEnable=1

Save the file.

The first line allows the Flash Debug player to write error and warning messages to the file, the second writes trace messages.

Create the flashlog.txt file

Well, let Flash do it for you.

  • If you have Flash installed:

Go to wherever you installed Flash (usually C:\Program Files\Adobe\Flash CS4) and open the Players\Debug directory. Run the FlashPlayer.exe file. That's it.

  • If you don't have Flash installed:

Run the flashplayer_10_sa_debug.exe file you downloaded above. Again, that's it.

This step is required because the Debug Standalone Player is what initially creates the flashlog.txt file where all of your trace() messages will end up. To verify that it's been created, look for it (in Windows) in C:\Documents and Settings\[username]\Application Data\Macromedia\Flash Player\Logs or the equivalent if you have some different install scheme.

Load your Flash file in a browser

You should see your trace messages output in all their glory in your flashlog.txt file. Ensure that you don't have trace messages being stripped from your Flash file in your Publish Settings!

Notes and Gotchas

  • By default ALL trace, warning, and error messages from ALL running Flash files in the current browser session are written to this file. It's best, therefore to preface all of your trace messages with some tag or indicator that they are yours, and from a specific application. I usually use a constant that I preface all of my trace messages with for easy identification.
  • Warnings and errors are very common in the file, you may want to set ErrorReportingEnable=0 in the mm.cfg file if you are just interested in trace messages.
  • DO NOT RUN ANY ADOBE AIR APPLICATIONS WHILE YOU ARE TRYING TO GENERATE TRACE OUTPUT! This one nearly drove me mad! The Flash Debug Player WILL NOT write flashlog.txt file if an Air file is running so you won't see any of your trace messages. Air files lock the flashlog.txt file when they run, effectively disabling all tracing. So, no matter how much you cannot live without it, make sure TweetDeck is not running (Twitter will wait, believe me) or you won't see squat. =)
  • If you want to monitor the file real-time without having to keep it open in an editor you can use cygwin's TAIL command to follow the file in a console window. First, install cygwin, then open a console window (Start | Run | cmd.exe) and type:
          tail /F /N50 [your path to flashlog.txt]

The console window will scroll and fill with your trace messages as they happen. If you use Aptana for web development its TailView feature is really handy for this as well. If you don't want to install cygwin or don't have Aptana installed this post describes how to get the same effect.

I found flashlog.txt to be a lifesaver. If anyone has any questions, just let me know.