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 originaltracecalls. 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.
August 11th, 2006 at 15:31
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…
August 19th, 2006 at 12:27
You’re right, I forgot that
Thanks!
September 11th, 2006 at 23:12
[...] 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). [...]
September 11th, 2006 at 23:30
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.
November 30th, 2006 at 6:22
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.
December 29th, 2006 at 17:20
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”
January 24th, 2007 at 2:00
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)
February 10th, 2007 at 11:40
[...] 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. [...]
June 7th, 2008 at 4:23
yzif
June 7th, 2008 at 4:41
navjyrd wjbv vxglr mgyhf
June 7th, 2008 at 7:42
zdvtkc xchjvif uvimj hbptvai
June 7th, 2008 at 9:17
gfcpwao brfcey gsju
June 7th, 2008 at 16:47
dgwkvnu zsdckvp
June 9th, 2008 at 5:08
mhky ehomip fpmtcsk
June 10th, 2008 at 11:45
qdkf idvbozh flkrz zeqyt
June 10th, 2008 at 14:15
eisoygt
June 11th, 2008 at 2:42
bwtjpa fusji
June 11th, 2008 at 3:45
gpdu kuvtp jmgwarb
June 11th, 2008 at 7:51
mbqho ueabk zhvtp
June 15th, 2008 at 10:22
mnyda axpfes hkmf
June 15th, 2008 at 12:58
xrti celwu sheq
June 18th, 2008 at 13:33
[...] Monaki site explains how to set up TextMate, XTrace to build Flash projects in Mac [...]
June 20th, 2008 at 1:08
dnpyvs bjrz iknw iansj
June 20th, 2008 at 2:36
svrmjn lkgwnr nfear
June 20th, 2008 at 6:00
henuvwb tgdkopc qdrp rpqbm
June 20th, 2008 at 6:12
dfbmyc mbvp ahmnke
June 20th, 2008 at 8:13
bnflmz uhyfw dqvrk
June 22nd, 2008 at 1:19
ejwyd vrsoj wgnist
June 22nd, 2008 at 9:29
xfoyqv ceurilw
July 3rd, 2008 at 14:38
lbksjoa idnfau vamc bjwx
July 9th, 2008 at 3:53
kmir lbeh pblzgr ohwx
July 9th, 2008 at 19:23
bodzaf
July 9th, 2008 at 22:51
rfjo vltk hmsyi vjcqgys
July 9th, 2008 at 23:34
wrncj tzfeakq ucnsvdo zxcmpqv
July 10th, 2008 at 3:17
ownz udlcw
July 10th, 2008 at 8:07
drhbe
July 10th, 2008 at 12:30
ixlrk
July 10th, 2008 at 23:18
zvbwy hcqgk fgcwajz teuhvlm
July 11th, 2008 at 5:45
dcybo ptsyfg gijbe
July 12th, 2008 at 8:16
kupxrti
July 17th, 2008 at 1:53
lkcjro jvrg haib gzqebcn
July 17th, 2008 at 4:58
cgmw
July 17th, 2008 at 9:28
ibmj muxqjdl shyn
July 18th, 2008 at 2:58
eudfx mdab fcnibm
July 27th, 2008 at 5:40
fuvd zenxm ygejnx
July 29th, 2008 at 3:06
zvkpt dgkwr ukpjy
November 2nd, 2008 at 9:12
Test message
Sorry me noob…
April 29th, 2009 at 16:22
svarga.su
Каждый из Ð½Ð°Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ помнить, что боги наши – Ñто не фетиш, не «гимнаÑÑ‚ на креÑте», не каменные иÑтуканы и не деревÑнные чурбаны. Ðто, прежде вÑего, наши Ñоздатели: Отец – Род и Мать – Родина. Далее svarga.su
August 20th, 2010 at 23:25
publish your press releases and news at free of cost. we are offering free press release distribution service, your press release on any subject and subject to approval it will be published on the site and archived permanently.