MTASC
Install | Usage | Tutorial | Download | MTASC and AS3 | Contact | Flash Comparison | Tell them!
![]() |
MTASC is the first ActionScript 2 Open Source free compiler. It can compile large number of You can download it now and please read the comparison between MTASC and Macromedia compiler that is sold with Flash. If it's your first time using MTASC, please read how to install and use MTASC. Please also visit the OSFlash community website. Get the MTASC logo for your website ! |
Install
Theses install notes are for windows user unfamiliar with commandline tools usage.
First download the MTASC package corresponding to your system and install/unzip somewhere on your computer. Then add the path of the installed executable to your PATH environment variable (see http://www.chem.gla.ac.uk/~louis/software/faq/q1.html if you don't kwnow how to do). For example if you've installed into c:\program files\mtasc
you might add c:\progra~1\mtasc
to your PATH. Now the executable is accessible everywhere. You can then write a compile.bat
file containing the following text :
mtasc.exe YourFiles.as... -swf YourProject.swf pause
Put the compile.bat
file with your source files and run it when you want to compile.
Usage
MTASC is a commandline compiler, it can then be better integrated into [Your favorite editor] by configuring it to compile .as
files with MTASC. The general usage of mtasc tool is : mtasc (your .as class files) -swf (you project swf)
. Please note that if you have two classes Point
and Line
with Line.as
using Point
for its code, you don't need to ask MTASC to compile Point.as
when compiling Line.as
since it will do it automatically for you. Then if you want to include the minimal set of classes needed by your program to run, you can simply compile using mtasc Main.as
where Main.as
is your "main" class, the entry point of your program (if you have any).
Now that you know how to call MTASC, let's have a look at how it works : MTASC takes the SWF file specified with the -swf
flag, compile all .as
specified files, and update the SWF file by replacing all classes that are present inside it by the newly compiled classes.
To use MTASC instead of Macromedia Flash Compiler, it's simple. Open your project and publish it normally (for example project.swf). Now run MTASC using the published SWF as input : mtasc (your as files) -swf project.swf
. This will compile your classes and update the SWF that you can use for your website. Please note that MTASC add the compiled classes to the SWF in replacement of ALL classes compiled by Flash.
If you have an error such as class not found, file not found, or class name mistake, you should use the -cp
flag in order to add a ClassPath to MTASC (that means a directory where it will look for .as files). For example if your classes are in the /code
directory, do not call mtasc code/Hello.as
because it will look for the class code.Hello
(with package code), but call instead mtasc -cp code Hello.as
.
Additional arguments are the following :
-swf file
: specify input SWF which contains assets.-cp path
: add a directory path to the ClassPath : this is the list of directories that MTASC will use to look for.as
files. You can use several times -cp to add several directories.-main
: will automaticaly call static functionmain
once all classes are registered.-header width:height:fps:bgcolor
: does not load a SWF, instead create a new one containing only compiled code and using provided header informations. bgcolor is optional and should be 6 digits hexadecimal value.-mx
: use precompiled MX classes (see section on V2 components below).
Some other arguments, for advanced users :
-version n
: specify SWF version : 6 to generate Player 6r89 compatible SWF or 8 to access Flash8 features.-v
: activate verbose mode, printing some additional informations about compiling process.-out file
: change output swf file.-msvc
: use Microsoft Visual Studio errors style formating instead of Java style (for file names and lines number).-strict
: will use strict compilation mode which require that all variables are explicitely typed.-exclude file
: exclude code generation of classes listed in specified file (format is one full class path per line).-trace function
: specify a custom trace function. (see Trace Facilities), orno
disable all the traces.-keep
: keep AS2 classes compiled by MCC into the SWF (this could cause some classes to be present two times if also compiled with MTASC).-frame f
: will export AS2 classes into target frame of swf.-pack path
: compile all the files contained in specified package - not recursively (eg to compile files inc:\flash\code\my\app
domtasc -cp c:\flash\code -pack my/app
).-group
: will merge classes into one single clip (this will reduce SWF size but might cause some problems if you're using -keep or -mx).-wimp
: adds warnings for import statements that are not used in the file.-infer
: adds type inference for initialized local variables (see below).
Tutorial
Once you know how to use MTASC commandline, here's a simple tutorial that show how it works. This first tutorial does not use any SWF content, only pure code. It contains only one Tuto.as
file, which prints some text into a Textfield :
class Tuto { static var app : Tuto; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 _root.createTextField("tf",0,0,0,800,600); // write some text into it _root.tf.text = "Hello world !"; } // entry point static function main(mc) { app = new Tuto(); } }
The only thing you need to do in order to run the sample is to call MTASC with the following arguments :
mtasc -swf tuto.swf -main -header 800:600:20 Tuto.as
The first parameter "-swf tuto.swf
" set the output file, the third parameter "-header 800:600:20
" tells MTASC to create a new SWF of size 800x600 at 20 FPS. The second parameter "-main
" tells MTASC to execute the entry point function main
once all classes are initialized, and the other parameter is the file to compile. If you need to compile several files you can list them in the commandline without any problem. Does NOT include paths into the files you're compiling with MTASC : use -cp
(see below).
If your code need to use a library with is located somewhere else on your hard drive, you need to use the -cp
commandline parameter so MTASC can find the classes your code is using. For example if you're using the class mx.controls.Button
which is located on your hard drive into C:\Program Files\Macromedia\Flash MX 2004\en\First Run\Classes\mx\controls
you need to execute the following command :
mtasc -cp "C:\Program Files\Macromedia\Flash MX 2004\en\First Run\Classes" ...
Does not forget to quote paths that contain spaces, and does not forget to remove paths from files when you're compiling them. If you want to compile the class app.File
that is located on your hard drive into C:\My Project\app\File.as
then run the following command :
mtasc -cp "C:\My Project" app\File.as
If you want to compile the whole package "app
" then use -pack app
commandline option, with additional -cp
if needed.
Download
You can download the MTASC compiler into the following formats/packages :
- Windows precompiled binary, zipped : mtasc-1.14.zip
- Linux precompiled binary : mtasc-1.12-linux.tgz
- Mac OSX package : mtasc-1.12-osx.zip
- Compilable sources (you need OCaml) : Install Documentation | Install OCaml Script.
Other tools :
- A Graphical User Interface made by Daniel Aguilar is available at http://www.protozoo.com.
- Another GUI, for MacOSX : http://www.telefonica.net/web2/xmtasc.
Contact
If you experience problems with MTASC usage, or if you have comments or features requests, you can join the mailing list. Archives are accessible so you can search for existing problems. If you don't want or can't use the mailing list or if you want to get information on support, you can also contact us using the following email address : ncannasse@motion-twin.com.
If you're looking for resources about more open source flash tools you have to visit the OSFlash.org website which contain a lot of informations. In particular, it nows host the MTASC FAQ on the Wiki.
Using Components (mx package)
It's possible to use Macromedia V2 Components with MTASC, but require an additional parameter : -mx
. Here's below a small tutorial on a basic component usage :
- let's write a small application using V2 Components, a single file called
Test.as
:class Test { function Test() { mx.controls.Alert.show("hello world","title"); } }
- open Flash IDE, create a new
test.fla
and add theAlert
component to the library. - Insert the following into the first frame :
t = new Test();
(this way it will create your application when started). - Publish into
test.swf
and test, a window should be displayed. - Passed this point you don't need Flash IDE anymore unless you want to use more components. Close it !
- modify your
Test.as
application code at will. - to recompile run the following command :
mtasc -cp "(your path to mm classes)" -mx -swf test.swf Test.as
where your macromedia path is something like :"c:\program files\macromedia\flash mx 2004\en\First Run\Classes"
- Enjoy fast compilation time !
MTASC and ActionScript 3
MTASC is very stable right now, so the releases since version 1.11 are focused on minor fixes and enhancements. Some people asked about the Future of MTASC, related to the next version of Flash 8.5 player and ActionScript 3.
MTASC will not support AS3, as we are currently working on a new and powerful language name haXe that will support Flash Players 6-7-8 and 8.5 as well as Javascript and Server-Side scripting.
You can check about it on haXe.org
Comparison with Macromedia ActionScript compiler
MTASC try to correct several safety problems that occurs when using Macromedia Compiler (MMC). It is a more strict compiler that can detect more errors and help you write better programs. Because of this, there might be a few differences between MMC and MTASC, and when you're compiling your code for the first time with MTASC you might get some errors.
However our goals are that MTASC users can easily :
- switch from MMC to MTASC, so the things you might have to fix in your code are just some minor things, easy and straightforward to modify, that will make your code safer.
- still compile with MMC : we're not planing to drive users from MMC into another lock-in solution. That means that MTASC is not making incompatible changes to the ActionScript language.
- Speed and Bugs :
MMC is awfully slow. It takes ages to compile large projects and the expected typing checks does not occur in some cases. It also sometimes forces you to restart your computer or compile several times to get a valid compilation (because of buggy cache, see http://www.actionscript.com/archives/00000591.html for more informations).
MTASC is based on the best compiler technology available (namely the OCaml programming language) and thus provide a great speed improvement over MMC (compile around 100 classes in less than 5 seconds). Since the source code is made more concise by using good technology, it is more easy to maintain and implement robust and proven typing algorithms. The feedback we get from Open Source community help us fixes the bug quickly.
Rationale : Does it really needs one ?
- Cost and TCO :
See article mentionned before to check how MMC can make you loose time (which is money). But if you're a professional ActionScript user, you already know that.
MTASC is free and open source. That means you can use it for free, modify the sources at your needs, and get bugfixes for free with each new version.
Rationale : We believe that open source will save the world, and your company programmers precious time.
- Local variables scoping:
With MMC (and more generally Flash Virtual Machine), local variables are function-local and not block-locals. That means that the following code :
function f() { var x = 1; if( true ) { var x = "hello"; // ... } trace(x+1); }
will not trace 2 but....
hello1
. And the following code is also working, although it shouldn't even compile in most traditional languages :function f() { if( true ) var x = 1; return x + 1; // what about the above is false ? }
Since the variable range is fixed into the Flash Virtual Machine, MTASC have to do deal with it, and is so forbidding local variable overidding, that means that you cannot redefine a local variable with the same name and that you cannot use a local variable outside of its normal scope. The following example illustrate this :
function f() { { var x : Number = 1; // ... use x as Number } // you cannot use x here { var x : String = "hello"; // ... use x as a String } // you cannot use x here }
Rationale : Variable scoping is necessary to get consistent typing and correct execution. Flash Virtual Machine lack of lexical scoping comes from previous AS1 language design, and MTASC is dealing correctly with it in order to avoid error-prone cases at compile time, saving long debugging times.
- #include :
MMC allows code file inclusion using the #include directive.
MTASC does not allow it.
Rationale : Such coding practices are obsoletes with ActionScript2, and the programmer should keep common duplicated code into separate classes.
- Local function definition :
MMC allows local named function definitions :
function f(x) { function g(y) { return x+y; } }
MTASC allows only anonymous (unnamed) local function definitions. They can be store into a local variable :
function f(x) { var g = function(y) { return x+y; } }
Rationale : in order for the parser to correctly checks that parenthesis are closed, it is necessary to distinguish between local functions definitions and method definitions.
- Tracing facilities
MMC only provides a single
trace
function that outputs some text in some output window (only in IDE). Because it's not very convenient, a lot of people are using custom loggers.MTASC uses this
trace
function that can be customized at compile time. For example if you have the following class :class Test { static function main(mc) { trace("hello world"); } }
Compiling using
mtasc -trace MyClass.myTrace Test.as (...)
will replace all calls oftrace
by calls to MyClass.myTrace (your custom trace function) and will add more parameters that contains debug infos, as if you wrote :class Test { static function main(mc) { MyClass.myTrace("hello world","Test::main","Test.as",4); } }
The three additionnal parameters are :
- Full class name with method name
- File name
- Line number
This way, it's very easy for your custom trace function for example to filter messages depending on the classes you want to debug. Please notice that
trace
with MTASC can takes any number of parameters and that debug infos are added after all other parameters.If you want to make a release version that does not contain any
trace
calls in the code, simply use "-trace no
" commandline flag when compiling and it will remove all calls. - Strictly typed arrays :
MTASC introduce a syntax extension that enables you to strictly-type your Arrays while still keeping AS2 compatibility :
var x : /*String*/ Array;
This variable is declared as an Array containing strings. All Array accesses for reading and writing will be then checked as if Strings where stored in the Array. This only do additional checks at compilation, nothing will change at runtime. Please be careful not to put spaces between /* and */. Please be also careful when initializing your Array since you can still use any Array to initialize it.
- Local variables type inference (-infer) :
If you use the
-infer
commandline parameter, when you have a local variable that have an initial value, then the type of the variable will be automaticaly bound to the one of the value :var x : String = "hello"; var x : Number = Math.cos(Math.PI); var x : MyClass = new MyClass();
For example, all theses statements can safely be replaced by the following when
-infer
is used, since they'll have the same effect :var x = "hello"; var x = Math.cos(Math.PI); var x = new MyClass();
You can use
-infer
with-strict
since you'll not get an error because missing type in that case only. - Other minor changes :
arguments
is supported, but not with dynamic access (such aseval("arguments")
for example).- with MTASC, getter return type and setter type parameter are required to be same (if specified).
- With MTASC, functions having no
return
statement are automatically typed as returningVoid
. - no support for initialization of member variables directly inside the class body (unless it's constant or static expression).
- with MTASC, "root" MovieClip properties are not accessible without context. For example if you use
_parent
in a class which does not have such property, you'll get an error. eval("this")
does not work.
MTASC logo for your website
You can use this little banner (88x31, GIF, 2k) to promote the MTASC free-compiler to the open source community: