Trace and debug ActionScript from your browser
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.View all articles by Josh Buhler
Written by : Josh Buhler - - joshbuhler.com
Difficulty Level: beginner
Topics Covered: debugging
Assumed Knowledge: How to install applications, edit and open text files.
How many times have you built something in Flash, tested it a million times or more, have it work great, and then fail as soon as you put it online, or outside the Flash IDE ? You then go back to your local version, test some more, and begin throwing trace("something here"); and trace("whyIsntThisWorking"); everywhere. It all works great, and then you put it online again, and it doesn't work. Personally, this seems to happen to me quite often on certain projects. I've often wished that there was some way to trace out what's going on in my .swf files online, so I can figure out what's happening.
Well, hallelujah, brothers and sisters, you can now do this, and I will testify unto you that it is almost a miracle. I've been trying to debug a project at work for about a week now, that used to work fine online, and now it doesn't. But using the technique below, I was able to trace out some info from the swf online, and figure out exactly where my problem was. This will also log errors such as undefined functions and variables for you as well, so this is a valuable tool. The cool thing about this is that it logs the info from any swf that you visit online. Just for fun visit a few Flash sites, and then open up the flashLog.txt file we'll create, and you'll see anything that they may have been tracing.
Disclaimer: I did not discover this on my own, so I can't take complete credit for it. I just thought it was an amazing debug tool, so I'm trying to spread the word. One day in my random travels around the web, I came across the following blog - g.wygonik's flash experiments Greg mentions that it's a Windows only tool, but I started playing around, and I've got it working just fine in OSX.
The secret comes from Macromedia Flex and it's debugging abilities. You don't need to have Flex for this to work, but all the documentation I could find from Macromedia is in the Flex help sections.
For this to work, you'll need to have the Flash Debug Player installed. This means that you'll need to uninstall your current Flash Player, and install the debug player instead. You can find an uninstaller here - http://www.macromedia.com/shockwave/download/alternates/ . You'll be able to find the Debug Player in your Flash install folder.
- For OSX users, you'll find it in /Applications/Macromedia Flash MX 2004/Players/Debug/Install Flash Player 7 OSX. app.
- Windows users, it'll be in a similar location. Usually in Start > Programs > Macromedia > Flash Player 7 > Debug. There are two versions of the player to install for Windows. IE requires the ActiveX installer (named: Install Flash Player 7 AX. exe) while other browsers (Opera, Mozilla, and so forth-) require the Flash plug-in installer (named: Install Flash Player 7.exe). Refer to the article above for Windows instructions.
Once you have uninstalled the Flash Player, and installed the Debug Player, you'll need to restart your browser, so bookmark this page. You can then verify that you have the Debug Player installed by right-clicking (control-click - just get a real mouse already Mac users ) on a swf. You should have the "debug" option in the context menu, like the example below. Once that's working, onto the next step.
Create a textfile called "mm.cfg". Inside the file, there are a few options for you. The most important options for this to work are below:
ErrorReportingEnable=1 TraceOutputFileEnable=1 TraceOutputFileName=MacHD:Users:username:Desktop:flashLog.txt MaxWarnings=50
Swapping "MacHD" with your computer name, and "username" with yours. You can put this wherever you want, just make sure you use the colons ":" and not slashes if you're using OSX. Windows users, same thing, put it where you want it, but you'll use "/" of course.
The firstline, ErrorReportingEnable=1 does just that - it enables error reporting. Then, TraceOutputFileEnable=1 enables the output file. You may be getting the idea now. The TraceOutputFileName is the path to where you want this file to be exported. I like to keep mine on my desktop. There are very few things that make it to my desktop, and this file is one of them, it's that cool. The MaxWarnings is the maximum amount of warnings you want reported. This doesn't limit your trace() statements, just the ActionScript warnings about undefined variables or methods. By default, this is set to 100, so you can leave this line out if you like. Or, you can set it to 0, and it there will be no limit placed. You can find more info about the options you have for this file in the Macromedia LiveDocs for Flex
Now, save this file, and place it in the following location:
- OSX users - MacHD /Library/Application Support/Macromedia/mm.cfg
- Windows - C:Documents and Settings username - follow the instructions in the link to Greg Wygonik above.
You don't need to create flashLog.txt, it will be created for you.
Now for the fun part. Open Flash, and create a quick movie with the following lines:
trace (" hello world ");
var something = 5;
trace (" something: " + someThing);
Publish the swf, and open it in your browser. Or, click the button below.
Now go to the location where you told the flashLog.txt file to be written to. Open this up, and you should see something similar to the following output:
Look at all the cool stuff you get - a warning that a function you're calling doesn't exist, variables being traced out, and a notice that you probably typed a variable wrong. Isn't this thing great? If you decide to make changes to your mm.cfg file, you'll need to restart your browser for those changes to take effect.Before you start debugging a file online using your flashLog.txt file, you'll want to make sure that you open it up and clear it out first. This doesn't always get emptied by Flash, and so you'll have trace info from multiple swf files all together in one file. If you just open it, select everything, delete it, and then resave the file, you can start with a clean slate to begin tracing to. If you have problems setting this up, post a comment below, and I'll try to respond as soon as I can.