Debugging with MTASC, Ant and Zeroi

Posted on March 4, 2007

In my previous posts "trace() outside the Flash IDE with tail" and "Are you looking for AFTERTHOUGHT on OS X?" I described two similar ways for debugging Flash movies outside the Flash IDE. In fact, it's relatively simple to use the Flash Debug Player in connection with the logging file called flashlog.txt but it has only got one big disadvantage: Instead of outputting structured data in predetermined levels you'll get tons of unstructured lines.

Introduction

A couple of weeks ago, I did this project on a team with Sönke Rohde. He showed me a better way for debugging Flash movies using Zeroi developed by himself and Ralf Bokelberg. Zeroi is a package of classes that supports MTASC's option for customizing trace() functions and the implementation of different log levels without changing code of your Flash application. You can use it with different debugging tools such as SOS, X-Ray or LuminicBox.Log. One of the most important feature is its ability to broadcast debug messages including additional information about class name, method name, line number and a error level with a standard trace() method.

For example: trace("i This is my message"); will be displayed as MyClass::myMethod Line>> This is my message. Additionally, you can add a character for an error level d = debug, i = info, w = warn, e = error, f = fatal.

Example

Click the buttons below to view the different debug messages.

To see this content latest Flash Player Plugin is required.

In this example the LuminicBox.Log is used as a debugger console. Open the LuminicBox.Log only once.

To see this content latest Flash Player Plugin is required.

Have a look inside the main class named ZeroiExample.as. It includes only standard trace() methods.

 1 /**
 2 * ZeroiExample
 3 * @author Jens Krause [www.websector.de]
 4 */
 5 import mx.utils.Delegate;
 6 class ZeroiExample
 7 {
 8  private static var example: ZeroiExample = null;
 9  private var __timeline: MovieClip;
10  function ZeroiExample(t: MovieClip)
11  {
12      trace ("i instance of ZeroiExample created");
13      __timeline = t;
14      initButtons();
15  }
16  private function initButtons (): Void
17  {
18      var labels: Array = ["debug", "info", "warn", "error", "fatal"];
19      for (var i : Number = 0; i <labels.length; i++)
20      {
21          var button: MovieClip = __timeline.attachMovie("button", "button" + i, __timeline.getNextHighestDepth(), {id: i, _x: i*100, _y: 30});
22          button.label.text = labels[i];
23          button.onPress = function () { ZeroiExample.instance.traceExamples(this.id); };
24      }
25  };
26  private function traceExamples ($id: Number): Void
27  {
28      switch ($id)
29      {
30          case 0:
31              // this is a debug message
32              trace ("d buttons id => " + $id);
33          break;
34          case 1:
35              // this is an info message
36              trace ("i buttons id => " + $id);
37          break;
38          case 2:
39              // this is a warn message
40              trace ("w buttons id => " + $id);
41          break;
42          case 3:
43              // this is an error message
44              trace ("e buttons id => " + $id);
45          break;
46          case 4:
47              // this is an fatal message
48              trace ("f buttons id => " + $id);
49          break;
50          default:
51              trace ("w $id has'nt defined");
52      };
53  };
54  public static function main (t: MovieClip) : Void
55  {
56      if (ZeroiExample.example == null) ZeroiExample.example = new ZeroiExample(t);
57  }
58 }

For creating the example above I've used the following Ant script. In the next chapter I'll give you detailed instructions to use Zeroi with Ant.

 1 <?xml version='1.0' encoding="utf-8"?>
 2 <project name="zeroi example" default="run" basedir=".">
 3  <description>
 4      buildfile for zeroi's example
 5  </description>
 6  <target name="deploy" description="Compiles an existing SWF file with MTASC for debugging">
 7      <!-- defines ant properties, you'll find more properties in "build.jk.properties" -->
 8      <property name="targetswf" value="zeroiExample.swf"/>
 9      <property name="mainclass" value="ZeroiExample.as"/>
10      <property name="classframe" value="1"/>
11      <property name="version" value="7"/>
12          <exec executable="${mtasc}" failonerror="true">
13              <!-- runs mtasc adding following arguments -->
14              <arg value="-version"/>
15              <arg value="${version}"/>
16              <arg value="-cp"/>
17              <arg value="${content.classpath}"/>
18              <arg value="-cp"/>
19              <arg value="${zeroi.classpath}"/>
20              <arg value="-cp"/>
21              <arg value="${core.classpath}"/>
22              <arg value="-swf"/>
23              <arg value="${deploy.folder}/${targetswf}"/>
24              <arg value="-frame"/>
25              <arg value="${classframe}"/>
26              <arg value="-main"/>
27              <arg value="${content.classpath}/${mainclass}"/>
28              <!-- adds zeroi's trace functions -->
29              <arg value="-trace"/>
30              <arg value="org.osflash.zeroi.logging.LoggerClass.log"/>
31              <arg value="org/osflash/zeroi/logging/LoggerClass"/>
32              <arg value="org/osflash/zeroi/logging/publisher/LuminicPublisher"/>
33          </exec>
34      </target>
35  <target name="run" depends="deploy" description="opens SWF">
36      <!-- opens the *.swf with the Flash Player (Standalone) -->
37      <!-- Note: The following command is for OS X users only, it won't run on windows -->
38      <exec executable="open" dir=".">
39          <arg line="-a ${flashplayer.v9} ${deploy.folder}/${targetswf}" />
40      </exec>
41  </target>
42 </project>

Instructions

All you need are MTASC, a debugger tool described above, Ant and the Zeroi package. It's recommend to use Eclipse and FDT as well.

  • Download the Zeroi example]) and unzip the file.
  • Grab the latest Zeroi package and unzip the file.
  • For this example you'll need the LuminicBox.Log, too. Download and open it. Note: Open the LuminicBox.Log only once.
  • Make sure, that you have installed MTASC successfully as described on mtasc.org. If you're on a Mac (PPC or Intel), you'll find the latest binaries (v.1.13) on MTASC's mailing list.
  • Open Eclipse, create a new Flash Project File -> New -> New Flash Project and link it to the folder "Zeroi example": First you have to uncheck use default location. Secondly, browse to the folder where the downloaded example is located.
  • Customize the property values in build.jk.properties and add this file to Ant's Preferences on Eclipse: Preferences -> Type "Runtime" in the search field -> Properties -> Add Files Note: Windows users have to change the target called "run" located in the build.xml as well. At present, it only runs on OS X. If there's anyone out there who's familiar with Ant on windows, feel free to post a comment for this issue.
  • On Eclipse open the Ant view Window -> Show view -> Ant, drag the build.xml located in the Flash Explorer to its Ant view and press the green button to run the script.

Eclipse Ant View

  • If you use other debugger tools, you'll only have to change one line located in build.xml
1 <!-- using XRay -->
2 <arg value="org/osflash/zeroi/logging/publisher/XRayPublisher"/>
3 <!-- OR -->
4 <!-- using SOS -->
5 <arg value="org/osflash/zeroi/logging/publisher/SOSPublisher"/>

Happy debugging ;-)

Any feedback?

comments powered by Disqus