If you code Flash and ActionScript you usually rely on the trace() function for debugging. A much better way is to use the free Powerflasher SOS (SocketOutputServer) which is a XML Socket server with a graphic user interface. Together with the mx.logging framework it is predestinated for logging and debugging your application and of course SOS can be used as a logging tool per se.
In the internet you can find a few classes to enable communication of your application with SOS. Of course you can write your own logging classes but in this tutorial the debugging will be explained using the classes written by Soenke Rohde. In the following debugging tutorial you will see how easy and useful working with SOS is and how much better it looks like normal trace() messages.
Let’s start…

  1. Download Powerflasher SOS from http://sos.powerflasher.de/english/english.html#downloads
  2. Download this swc or download the sources from http://soenkerohde.com/2006/11/06/flexas3-logging-with-sos
  3. Start your eclipse in the FDT perspective and create a New Flash Project with the name “SOS Logging”. A good approach is to add a new folder to your application directory named “lib” and copy the swc-file into it.
  4. Right-click on the swc in your lib-folder and choose “Source Folder” and “Add to Classpath”. Now, FDT allows you to browse through the swc in your Flash-Explorer while clicking on the little arrows in front of it.
    Workfolder
  5. The first part is finished. Now let’s write a little HelloWorld-application.
    Add a new source folder named “src”, create a new class named “SOSLogging” and write some code like the following:

    package
    {
         import flash.display.Sprite;
         import flash.text.TextField;
         import flash.text.TextFieldAutoSize;
    
         /**
         * @author Stephan Partzsch
         */
         public class SOSLogging extends Sprite
         {
    
              public function SOSLogging() : void
              {
                   var textField:TextField = new TextField();
                   textField.autoSize = TextFieldAutoSize.CENTER;
                   textField.text = "Hello world!";
                   this.addChild(textField);
              }
         }
    }
  6. Now it is time to add the logging commands. First you have to create a variable of type SOSLogger, add a new instance of the SOSLogger to it and pass the name of your class. That allows you to see which class generates which logging-message. The added code is highlighted in the following example.
    package
    {
         import flash.display.Sprite;
         import flash.text.TextField;
         import flash.text.TextFieldAutoSize;
         import com.soenkerohde.logging.SOSLogger; 
    
         /**
         * @author Stephan Partzsch
         */
         public class SOSLogging extends Sprite
         {
              private var _logger : SOSLogger;
    
              public function SOSLogging() : void
              {
                   _logger = new SOSLogger("SOSLoggingClass");
    
                   var textField:TextField = new TextField();
                   textField.autoSize = TextFieldAutoSize.CENTER;
                   textField.text = "Hello world!";
                   this.addChild(textField);
              }
         }
    }
  7. As of now you can organize your work with multicoloured logging messages. For each command a specific colour can be defined. To customize your logging messages press Strg/Ctrl + Y in your SOS.
    The following code shows some logging commands.

    package
    {
         import flash.display.Sprite;
         import flash.text.TextField;
         import flash.text.TextFieldAutoSize;
         import com.soenkerohde.logging.SOSLogger;
    
         /**
         * @author Stephan Partzsch
         */
         public class SOSLogging extends Sprite
         {
              private var _logger : SOSLogger;
    
              public function SOSLogging() : void
              {
                   _logger = new SOSLogger("SOSLoggingClass");
    
                   var textField:TextField = new TextField();
                   textField.autoSize = TextFieldAutoSize.CENTER;
                   textField.text = "Hello world!";
    
                   _logger.debug("My text: " + textField.text);
                   _logger.error("My text: " + textField.text);
                   _logger.info("My text: " + textField.text);
                   _logger.warn("My text: " + textField.text);
                   _logger.fatal("My text: " + textField.text);
    
                   this.addChild(textField);
              }
         }
    }
  8. All you have to do to see your first Powerflasher SOS logging message, is to start your SOS and then run your application by pressing Alt+Shift+X followed by M.

The whole project can be downloaded here.

That’s it and I hope it helps you to code your applications a bit easier.
Stephan