Using Debugger And Print To Debug Your ActionScript Under Linux

firebug-debugIn previous article Using Actionscript 3 to develop Adobe Flash Content On Linux(Chinese Version), we have tried to use Adobe Flex 3.0 SDK developed “hello actionscript 3″ under Linux successfully. Compared with Windows programmer, the debug for Linux programmer is more complex. Especially for these user only use the Adobe Flex 3.0 SDK, it is more difficult. But it doesn’t mean the weak function. On the contrary when you get used to Linux gdb (Flex 3.0 SDK fdg), you will find that it could following your own thinking to debugging program under Linux. Which different from the windows, you need to following the result of debugging program. Then, less nonsense. Let’s begin our travel of Debug under Linux immediately.  

The way of Linux Debug

There are generally two ways as following, we will introducing them individually: “Use debugger” and “The most primitive way: print”.

・Use debugger

The use of debugger which is the way using the tool fdb in Adobe Flex 3.0 SDK to debug our program.

・Installation

You should have installed flashplayer in you system. It have been include in the Adobe Flex 3.0 SDK which we mentioned on Using Actionscript 3 to develop Adobe Flash Content On Linux.

Input following command for installation:

$ tar xvfz flex/runtimes/player/lnx/flashplayer.tar.gz
$ sudo cp flashplayer /usr/bin

・Direction of fdb

To use the fdb debugging the swf file, swf file must contain the information which do the debugging needed. Then when compile by mxmlc, we need add the option debug=true. The Makefile as following:

MXMLC = /tmp/flex/bin/mxmlc
MFLAGS = -debug=true

TARGETS  = hello.swf

all: $(TARGETS)

clean:
        $(RM) $(TARGETS)

.SUFFIXES:      .as .swf
.as.swf:
        $(MXMLC) $(MFLAGS) $<

Then the compiled swf file will contain the information which debugging needed. Input the following command to open the swf file for debugging.

$ fdb  hello.swf

Then following opation is as same as gdb.

・Help — “h”

・re-open — “c”

・set breakpoint — “b function-name”

・view source code — “list”

・view variable — “print variable”

We also could run fdb by emacs, the operation is:

・M-x gdb

・fdb hello.swf

The next step is as same as before.

・The way using print to debug

・use trace()

trace() is the function which output the debugging information for ActionScript. The use way as below:

package {
    import flash.display.*;
    public class hello extends Sprite {
        public function hello () {
            trace("hello");
        }
    }
}

If the upper code run under the flashplayer, should be:  

$ flashplayer hello.swf
hello

Then output the hello. What more important and must to explain is trace() just effective on the debug version of player or plugin. Both general version and devloper(debug) version could be downloaded:

・Under Flex SDK runtimes

http://www.adobe.com/support/flashplayer/downloads.html

But it is still more inconvenient if need intall the special debug version.

・Way of gearing with JavaScript

Besides the trace(), there is another way which using the JavaScript function to output by client browser from swf file.

package {
    import flash.display.*;
    import flash.external.ExternalInterface;

    public class hello2 extends Sprite {
        public function hello2 () {
            ExternalInterface.call('alert', "message");
        }
    }
}

In fact it calls the alert function of JavaScript and show the “massage” by dialog box.

・The way use firebug

Since the JavaScript could do the debugging, of course we can use the firebug to debug it.

The detail of use way could reference firebug document. What need to be special explained is that if use firefbug it could format output as printf by function log(). For example: 

ExternalInterface.call('console.log', "string is [%s]“,  “abcde”);

The following code is valuable part written on this basic. log.as

package {
  import flash.external.ExternalInterface;
  import flash.utils.getQualifiedClassName;

  public function log(... args):void {
    var inspect:Function = function(arg:*, bracket:Boolean = true):String {
        var className:String = getQualifiedClassName(arg);
        var str:String;

        switch(getQualifiedClassName(arg)) {
            case 'Array':
              var results:Array = [];
              for (var i:uint = 0; i < arg.length; i++) {
                  results.push(inspect(arg[i]));
              }
              if (bracket) {
                str = ‘[' + results.join(', ') + ']‘;
              } else {
                str = results.join(’, ‘);
              }
              break;
            case ‘int’:
            case ‘uint’:
            case ‘Number’:
              str = arg.toString();
              break;
            case ‘String’:
              str = arg;
              break;
            default:
              str = ‘#<’ + className + ‘:’ + String(arg) + ‘>’;
        }
        return str;
    }

    var r:String = inspect(args, false);
    trace(r)
    ExternalInterface.call(’console.log’, r);
  }
}

Save as “log.as” and add in source-path of flex-config.xml.

<source-path>
        <path-element>/home/tei/flex2/libs</path-element>
</source-path>

Then use the log() directly, for example:

package {
    import flash.display.*;
    import flash.external.ExternalInterface;

    public class hello extends Sprite {
        public function hello () {
            log("hello");
        }
    }
}

If put log.as under the same direction, the Makefile could be write as below:

MXMLC = /tmp/flex/bin/mxmlc
MFLAGS = 

TARGETS  = hello.swf

all: $(TARGETS)

clean:
        $(RM) $(TARGETS)

.SUFFIXES:      .as .swf
.as.swf:
        $(MXMLC) $(MFLAGS) $<

hello.swf: log.as
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

4 Responses to “Using Debugger And Print To Debug Your ActionScript Under Linux”

  1. [...] Using Debugger And Print To Debug Your ActionScript Under Linux By minidxer On the contrary when you get used to Linux gdb (Flex 3.0 SDK fdg), you will find that it could following your own thinking to debugging program under Linux. Which different from the windows, you need to following the result of debugging … Ntt.cc – http://ntt.cc [...]

  2. [...] public links >> flex2 Using Debugger And Print To Debug Your ActionScript Under Linux Saved by Naomi2494 on Mon 27-10-2008 Adobe Flex2 Component Explorer Saved by thisandthat on Tue [...]

  3. nice says:

    perfect thanks!

Leave a Reply