I’ve been testing out MTASC recently. I started trying to use it for some large projects, but was running into a learning curve on getting all the class paths and so forth all in a row. I had deadlines and couldn’t afford to mess around with it, so shelved it for a while.
But now I have a little time on my hands and jumped back into it. One of the biggest annoyances was trying to fit all that stuff on the command line. I have a few different class paths going on, and my command line was getting rather long. Of course I was putting it in a batch file, but it was still getting unweildy.
So I dug up some old batch file tricks and got it down to a system.
I use PrimalScript, and found that it integrates quite well with MTASC. I got a few tips from Robert Penner the other week in Toronto as well. Here’s the flow:
1. In PrimalScript, go to Tools/Options/Environment/Languages/ActionScript. In the “Selet a Category” dropdown, choose “Script Interpreter”. In the box below that, enter “$ProjectFolder$\compile.bat” (without the quotes). Also check “Capture Output” at the bottom of the dialog.
2. Now when you make a project, create a new text file named “compile.bat” in the root of the project directory. Now, when you hit F7 while in a project, this compile.bat file will execute. You have a couple of choices here. If you want the Flash IDE to compile whatever fla file is open, you can add the following to your compile.bat:
@"c:Program FilesSapienPrimalScriptFlashDriver.exe" compile.jsfl
But, if you want to use mtasc instead, here’s what you put in compile.bat:
@echo off set cp1="c:Documents and Settings\Local SettingsApplication DataMacromediaFlash MX 2004enConfigurationClasses" set cp2= set cp3= set swf=..deploymyapplication.swf set class=MainClass.as mtasc -cp %cp1% -cp %cp2% -cp %cp3% -mx -swf %swf% %class% if errorlevel 1 goto end %swf% :end
What this does is set variables for as many class paths as you want, a variable for your main swf and main class. It then uses these variables to compose the command line. Finally, it checks the return value of the call to mtasc. If it compiled successfully, this will be 0, and the batch file will load the swf. If not, it will jump to the :end label and display whatever error it ran into. The cool thing is that you can then double click on that error line and PrimalScript will open up the offending .as file and go right to the problem line!
Note that you can include just a single class path (or none) or as many as you want. Just set the variables and alter the command line as appropriate. Also notice that you can use file paths to your swf. I publish mine in a deploy directory on the same level as my source directory (which is where my project is). So my swf variable is ..\deploy\myapplication.swf
When you’ve got it how you want it, hit F7 and there’s your swf! (or your error message.)
Third Party Components.
I don’t use MM components. I use the BeamJive Bit components (which I made). At first I was having a lot of problems with these in mtasc. If you use the MM components, the -mx switch takes care of you. If you are using a third party set like this, or custom components you have made, you need a path to the class files, or at least the intrinsic files. The BeamJive set does install intrinsic class files. I think the default path is the same as the first class path listed above. But I’ve put mine in another location, which I use my second class path for.
Even if you have the class paths for your components set up correctly, you may still get warnings. This is because sometimes the components use other sub-components, whose classes are not directly referenced in your swf. The easiest way I’ve found to handle that is just to copy the class paths from the warning messages and add them as import statements in your main class. Even though that class may not use them directly, they will be included in the swf and handle any warnings or errors.
Under informal testing, I had a fla that takes 7 seconds to compile in Flash. With the above setup, it’s somewhere around 2 seconds. Too quick to measure exactly.
There are GUI’s for both mac & windows:
Windows: http://www.protozoo.com/index.php?month=December
Mac: http://www.telefonica.net/web2/xmtasc/
I’ve been using the mac gui in combination with a small script i wrote to automatically compile & view the current project in Xmtasc from Xcode (the scripts on my blog). I’m sure you could probobly do something similiar in windows.
Yes, those guis are plainly referred to in the mtasc documents. But the whole idea of having a command line compiler that integrates with your editor is so you can compile straight from the editor with the push of a button. If I’m going to have to switch back and forth to a gui, I might as well continue to use Flash.
Thanks for the ideas. I came up with a different approach to the same task a few weeks ago. I’ve been meaning to write something up, so following your lead I put it up:
http://probertson.com/articles/2005/04/21/mtasc-and-primalscript/
I was trying to avoid the external .bat approach, so I did it a bit differently; and I think the different approaches have some advantages and disadvantages.
Nice implementation. I agree it’s a bit of a pain to make a batch file each time, but I have a template that I can just throw in the names of my classes and swf. And I love the ability to do multiple calls to mtasc to compile multiple swfs, all with conditional branching – if one fails, you just go to end and display the error. And this allows the introduction of other command line tools into the batch. Such as swfmill, preprocessors, who knows what else.