Using Textmate, MTASC and XTrace to build Flash projects in Mac OSX

In this post I will describe my workflow for developing Flash projects without the use of the Adobe Flash IDE. This workflow isn’t suitable for every project. It’s mainly of use for those projects which only contain pure Actionscript code and make no use of components, objects in the library or non-scripted motion tweens. After following the instructions, you will be able to do the following:

  • Compile Actionscript .AS-files to a .SWF-file from within Textmate.
  • Preview .SWF-file from within Textmate.
  • Display error messages from within Textmate. You can click on these messages to quickly jump to the source of the error.
  • Display “trace” commands in a seperate window which automatically fades away after 30 seconds.


For all this to work, you’ll need this:

  • Textmate – Text editor.
  • MTASC – ActionScript 2 Open Source free compiler.
  • XTrace – Displays “trace” commands to debug your project.

Installation of the programs

First you have to install Textmate and MTASC. The installation of Textmate is straightforward. I’ll leave it up to you. The installation of MTASC is easy as well. Just unzip the file you’ve downloaded from the site mentioned above and copy the files into a folder of your choice. I chose “/Developer/Mtasc”.

XTrace is downloadable as a .ZIP-file. It contains an application file “Xtrace.app” and the Actionscript class “debug.as” in the folder “ASTest/com/mab/util”. I copied the application to my general application folder, and the directory “com” to “/Developer/Mtasc/”.

Scripting the compiling process

The following code needs to be saved in a text file called “build.sh”. You can copy-paste the text below into a file, or you can download build.sh.

	
#! /bin/sh

FLASHPLAYER=SAFlashPlayer
MTASC=/Developer/Mtasc/mtasc
CLASSES=/Developer/Mtasc/std8/
SOURCE=mainProgram.as
OUTPUT=mainProgram.swf
HEADER=550:400:40:ffffff
VERSION=7
TRACE=-trace\ com.mab.util.debug.trace
TMPFILE=/tmp/mainProgram.err

if [[ $1 == "-t" ]]; then
	$MTASC -cp "$CLASSES" -swf $OUTPUT -version $VERSION -header $HEADER -wimp $TRACE -main $SOURCE 2>&1 | grep characters | grep -v "Warning unsupported #include" | perl -pi -e "s/^(.+?):(.+?): characters (\d+?)-\d+? : (.*)\$/<a href='txmt:\\/\\/open?url=file:\\/\\/${TM_PROJECT_DIRECTORY//\//\\/}\\/\$1&line=\$2&column=\$3' onClick='closeWin()'>${TM_PROJECT_DIRECTORY//\//\/}\/\$1:\$2: \$4<\/a>/g"

else
	$MTASC -cp "$CLASSES" -swf $OUTPUT -version $VERSION -header $HEADER -wimp $TRACE -main $SOURCE
fi
	

Explanation

The file “build.sh” has to be placed in the root of your project folder. You can alter the following variables for your project:

  • FLASHPLAYER – Application name of the flash player.
  • MTASC – Link to MTASC.
  • CLASSES – Link to the Actionscript classes you want to include in your build.
  • SOURCE – Relative link to the main actionscript source file.
  • OUTPUT – Relative link to the output of the compiled .SWF file.
  • HEADER – Header describing the dimensions and frame rate of your .SWF file.
  • VERSION – Compile the .SWF-file as the defined version.
  • TRACE – Define a replacement function of the original trace calls. I used XTrace’s function here.
  • TMPFILE – Absolute link to the temporary file containing error messages.

As for the rest of the code: if build.sh is called without arguments, the source is compiled using Mtasc. If build.sh is called with argument “-t”, your project is compiled for use in Textmate. Basically, what this (very hard to read) command does, is filtering out all the warnings of unsupported #include’s, and wrap all error messages in standard HTML anchors, to quickly jump from Textmate’s error window to the location of the error in your files. This part of the script was copied from a post of Ben Jackson.

Preview .SWF-file from Textmate

To execute the compiled .SWF-file from Textmate, the script below has to be implemented as a Textmate command. I Used the following options:

  • Save: “All Files in Project”
  • Command(s): copy-paste from below or download runScript.sh
  • Input: “None”
  • Output: “Show as HTML”
  • Activation: “Key Equivalent”: “COMMAND-ENTER”
	
FLASHPLAYER="`cat $TM_PROJECT_DIRECTORY/build.sh | grep -m1 FLASHPLAYER= | sed 's/FLASHPLAYER=//'`"

TMPFILE="`cat $TM_PROJECT_DIRECTORY/build.sh | grep -m1 TMPFILE= | sed 's/TMPFILE=//'`"
OUTPUT="$TM_PROJECT_DIRECTORY/`cat $TM_PROJECT_DIRECTORY/build.sh | grep -m1 OUTPUT= | sed 's/OUTPUT=//'`"

touch $TMPFILE

cd $TM_PROJECT_DIRECTORY
$TM_PROJECT_DIRECTORY/build.sh -t > $TMPFILE

echo "
	<style type='text/css'>

		body {margin: 10px; font-family: Courier New; font-size: 12px;}
		a {color: #666666; text-decoration: none;}
		a:hover {color: #f00;}
	</style>
	<script type='text/javascript'>
		function closeWin() {
			self.close();
		}
	</script>
"

if test -s $TMPFILE; then
	echo "<body>`cat $TMPFILE`</body>"

else
	echo "<body onload='closeWin()'></body>"
	osascript -e "tell application \"$FLASHPLAYER\" to quit"
	open -a $FLASHPLAYER $OUTPUT
fi
	

Explanation

This script first reads some variables from “build.sh” and it creates an empty temporary error file. Then it tries to compile your project. If compiling succeeds, it tells Textmate to close the output window and refresh the Flashplayer window. Else, it displays each error message in the Textmate output window. You can click on these messages to quickly jump to the line in your program containing the error.

Typical workflow

When starting a project, you’d typically copy “build.sh” to your project folder. Then you’d adjust the variables to suit your needs. Launch XTrace.app, and start coding away in Textmate. While an .AS-file in your project folder is selected, you’d hit “COMMAND-ENTER” to preview the .SWF-file.

49 Responses to “Using Textmate, MTASC and XTrace to build Flash projects in Mac OSX”

  1. ryan Says:

    Got it up and running – but thanks for the great info. My main comment so far – the “build.sh” file needs to be chmod’ed for execution as a shell script in the terminal (sudo chmod a+x pathtobuildscript). I know you know that ;) , but it took a couple of minutes for it to dawn on me why I was getting a permission denied error…

  2. Wimer Hazenberg Says:

    You’re right, I forgot that :) Thanks!

  3. dirtystylus » Blog Archive » TextMate/MTASC/XTrace Revisited Says:

    [...] I came upon this post at Wimer Hazenberg’s Monokai blog a while back, tried it, and shelved it when I couldn’t get XTrace to work with files I’d placed on a webserver. I’ve since worked out the XTrace issue (a crossdomain policy served from my Mac’s localhost did the trick) so I decided to take some time to re-investigate the TextMate/MTASC/XTrace workflow. So here are two Textmate Actionscript commands that I whipped up based on that Monokai post. My goals were not to do project-level compiles, but instead incremental syntax checks with MTASC and simple single-swf compiles. These commands assume that you have MTASC and XTrace installed and working (see the Monokai post for more on both of those). Note that I placed the MTASC folder in /Users/domanistudios/opt/, which you can see from the variable declarations in the commands. The first command calls MTASC with no output swf, and dumps the first error to an HTML ouput window (I believe mtasc only reports the first error it encounters during a compile). Using the built-in TextMate url functionality, clicking on the error will return you to the document you were editing, at the line where the error was encountered (so far haven’t figured out how to get it to go to the proper character, though). Note that you can also modify the actual line that does the compile to add/delete arguments (like -strict). [...]

  4. dirtystylus Says:

    I see auto-trackback blog notification beat me to the comments. Thanks again for posting the details on your workflow. I was able to take the commands and modify them for my own purposes – most importantly incremental compiles (syntax checking!) without swf output.

  5. tfarnon Says:

    If you install the Developer Tools, you can add the following to the very bottom of your TextMate command:

    /Developer/Tools/SetFile -c ‘SWF2′ -t ‘SWFL’ $OUTPUT

    It sets the type & creator of your freshly-rendered .swf so there’s a proper Flash Player document icon associated with it.

    It also helps those inclined to double click their new .swf so the standalone Player launches.

  6. meen Says:

    When using the build.sh script it throws

    /Users/meen/Desktop/personal/flashApp/build.sh: line 11: com.mab.util.debug.trace: command not found

    I’m not very deft at shell scripts but adding double quotes to the TRACE value on line 11 seems to remedy this.

    TRACE=”-trace com.mab.util.debug.trace”

  7. thiago demello bueno Says:

    How would i go about adding multiple class paths? Or is that still done when you export from flash the first time (which seems less than ideal)

  8. Practical Guile » Blog Archive » Using Textmate for Actionscript Says:

    [...] I’ve never liked the default code editor that comes with the Flash IDE, so when the I discovered that I would need to develop actionscript code for a project, my first thought was to use Textmate instead. Incidentally, some people are already doing this. [...]

  9. karaoke show tunes Says:

    yzif

  10. father sday Says:

    navjyrd wjbv vxglr mgyhf

  11. pokemon karaokemon Says:

    zdvtkc xchjvif uvimj hbptvai

  12. karaoke machine singing starz video Says:

    gfcpwao brfcey gsju

  13. karaoke7586 Says:

    dgwkvnu zsdckvp

  14. comet oreck vacuum cleaner rating Says:

    mhky ehomip fpmtcsk

  15. junior plus size swimsuits Says:

    qdkf idvbozh flkrz zeqyt

  16. soft cup swimsuit Says:

    eisoygt

  17. matzo cake meal Says:

    bwtjpa fusji

  18. birth control effects pill side yasmin Says:

    gpdu kuvtp jmgwarb

  19. conscience clause birth control Says:

    mbqho ueabk zhvtp

  20. mothers day gift ideas ireland Says:

    mnyda axpfes hkmf

  21. happy mothers day Says:

    xrti celwu sheq

  22. XTRACE, MTASC and TextMate « factornine weblog Says:

    [...] Monaki site explains how to set up TextMate, XTrace to build Flash projects in Mac [...]

  23. hilton niarchos paris Says:

    dnpyvs bjrz iknw iansj

  24. paris hilton one night in paris free video Says:

    svrmjn lkgwnr nfear

  25. fasbnet.com hilton hilton news paris paris promote video Says:

    henuvwb tgdkopc qdrp rpqbm

  26. paris hilton home movie download Says:

    dfbmyc mbvp ahmnke

  27. paris hilton shocking picture Says:

    bnflmz uhyfw dqvrk

  28. day2237 Says:

    ejwyd vrsoj wgnist

  29. father day monogram Says:

    xfoyqv ceurilw

  30. cheap sunglasses zz top Says:

    lbksjoa idnfau vamc bjwx

  31. soft shelled clam steamer Says:

    kmir lbeh pblzgr ohwx

  32. book coloring day father Says:

    bodzaf

  33. henny youngmans father day jokes Says:

    rfjo vltk hmsyi vjcqgys

  34. father day gifts from baby Says:

    wrncj tzfeakq ucnsvdo zxcmpqv

  35. what date is fathers day Says:

    ownz udlcw

  36. church day father poem Says:

    drhbe

  37. art projects for fathers day Says:

    ixlrk

  38. animal wellness magazine Says:

    zvbwy hcqgk fgcwajz teuhvlm

  39. origins wellness service Says:

    dcybo ptsyfg gijbe

  40. hotbabes Says:

    kupxrti

  41. light pedal Says:

    lkcjro jvrg haib gzqebcn

  42. visual boy advance Says:

    cgmw

  43. swinger personals Says:

    ibmj muxqjdl shyn

  44. barnes noble Says:

    eudfx mdab fcnibm

  45. Wedding March Song 823 Says:

    fuvd zenxm ygejnx

  46. dvd duplication Says:

    zvkpt dgkwr ukpjy

  47. avafeEreftmor Says:

    Test message
    Sorry me noob…

  48. svarga.su Says:

    svarga.su
    Каждый из нас должен помнить, что боги наши – это не фетиш, не «гимнаст на кресте», не каменные истуканы и не деревянные чурбаны. Это, прежде всего, наши создатели: Отец – Род и Мать – Родина. Далее svarga.su

  49. beach bunny swimwear xs Says:

    Please let me know if you’re looking for a writer for your site.
    You have some really great posts and I believe I would bbe a good asset.
    If you ever want to take some of the load off, I’d absolutely love to write some articles for your blog in exchange for a link back too mine.
    Please blast me aan email if interested.Many thanks!

    Stopp by my web site beach bunny swimwear xs

Leave a Reply