Skip to content
hydroper edited this page Jun 4, 2019 · 10 revisions

Compiling Programs

Redtamarin "as is" is not a compiler.

The Redtamarin shell or redshell can interpret 3 types of file

  • ABC files
    ActionScript ByteCode binaries
  • SWF files
    Shockwave Flash binaries
  • ActionScript 3.0 files
    raw AS3 source code (not compiled)

Obtain a Compiler

You will need to download and install either

  • the Redtamarin SDK
  • the Adobe Flex SDK
  • the Apache Flex SDK
  • the Adobe AIR SDK

All those SDK and compilers depends on Java so you will need to have Java installed.

The Redtamarin SDK

Our SDK provide asc.jar and asc2.jar as well as the redbean command-line tool.

Those are the strict minimum and the easiest tools to compile for redtamarin under Windows, Mac OS X and Linux.

Install the Redtamarin SDK.

note:
asc.jar is a special old version used during the development of tamarin-redux
that is more convenient for us to compile native libraries.
ftp://ftp.mozilla.org/pub/js/tamarin/builds/asc/latest/asc.jar (not available anymore)
https://ftp.mozilla.org/pub/js/tamarin/builds/asc/latest/asc.jar
asc2.jar is a ASC v2 taken from the CrossBridge project.
crossbridge/tools/lib/

The Adobe Flex SDK

The project started in 2006 and then Flex was donated to the Apache Software Foundation at the end of 2011.

You can still find the Flex SDK v4.6 on Adobe site, as it is the one installed by default with Flash Builder 4.6, 4.7, etc.

Download Adobe Flex SDK.

The Apache Flex SDK

Since 2011, after an incubation period, the Flex project is officially maintained by the Apache Foundation.

Download Apache Flex SDK.

The Adobe AIR SDK

Adobe keep developing and releasing a AIR SDK which contains the ActionScript Compiler 2.0.

Download Adobe AIR SDK.

Compiling with Java

You can reuse any asc.jar from any SDK, any should work by default.

But depending on which SDK you use the ASC may have slightly different options and/or capabilities (which would only matter if you do super duper advanced stuff).

The ActionScript Compiler can be invoked in different ways

$ java -jar asc.jar [options] myfile.as

$ java -classpath asc.jar macromedia.asc.embedding.ScriptCompiler [options] myfile.as

Here some examples:

$ java -jar asc.jar -AS3 -import builtin.abc -import toplevel.abc helloworld.as

$ java -jar asc.jar -abcfuture -builtin -apiversioning -import builtin.abc shell_toplevel.as Domain.as ByteArray.as ...

$ java -ea -DAS3 -DAVMPLUS -classpath asc.jar macromedia.asc.embedding.ScriptCompiler -abcfuture -builtin -apiversioning -import builtin.abc -out shell_toplevel shell_toplevel.as Domain.as ByteArray.as ...

Some functionalities can be only activated using the ASC 2.0, for example if you need to use fastmem op (see Faster byte array operations with ASC2).

Once you have installed the Redtamarin SDK you could for example use a bash script

#!/bin/bash
ASC=/usr/lib/redtamarin/support/asc.jar
redtamarin=/usr/lib/redtamarin/lib/redtamarin.abc
java -jar ${ASC} -AS3 -import ${redtamarin} helloworld.as

Important Things to Know

First and foremost, ASC is not MXMLC, there are simply a different set of rules.

1. ASC will not automatically include files for you

Let's say your Program.as have 2 dependencies ClassA.as and ClassB.as by just using the keyword import those dependencies will not be compiled, you have to manually include them.

$ java -jar asc.jar Program.as will fail

$ java -jar asc.jar ClassA.as ClassB.as Program.as will work

or you can also use the include directive, for example

include "ClassA.as";
include "ClassB.as";

package
{
    import ClassA;
    import ClassB;

    public class Program
    {
        //...
    }
}

$ java -jar asc.jar -import ClassA.abc -import ClassB.abc Program.as will also work

2. ASC will not execute the default class for you

When you compile with MXMLC you define a "default class" that is used to compiel a SWF, but is also instantiated by default, not with ASC.

Let's take this example

package
{
    public class Program
    {
        trace( "hello world" );
    }
}

$ java -jar asc.jar Program.as will compile a Program.abc without errors.

but when you will run the program with $ redshell Program.abc nothing will execute.

You need to tell which class/function/etc. to execute

package
{
    public class Program
    {
        trace( "hello world" );
    }
}

new Program(); //here

3. ASC is less strict concerning class definitions

With Flash Builder, MXMLC, etc. you need to have 1 public definition per file otherwise the IDE, compiler will complain.

Not with ASC, you can have no definitions at all, multiple definitions, etc. it will work

Very basic script with no definitions

trace( "hello world" );

Script with multiple definitions

package test
{
    public class ClassA
    {
        //...
    }
}

package something
{
    public class ClassB
    {
        //...
    }
}

package
{
    import test.ClassA;
    import something.ClassB;

    public class Program
    {
        //...
    }
}

new Program();

In fact, compc also allows such freedom with the --include-sources option; e.g., $ acompc --include-sources src takes every .as under src and puts no restriction on every script. However, because it produces a unified DoABC SWF-tag, Red Tamarin interpreter may crash.

4. ASC will not merge dependencies for you

With MXMLC, if you use some SWC libraries and then compile a SWF, MXMLC will automatically include the bits you are using from the SWC libraries into the final SWF.

With ASC, you can compile with ABC libraries (using -import), but the final ABC file will not have the libraries ABC included.

$ java -jar asc.jar -import ClassA.abc -import ClassB.abc Program.as will compile

but $ redshell Program.abc will fail as it misses 2 ABC libraries.

To run this program you will need to pass along the dependencies
$ redshell ClassA.abc ClassB.abc Program.abc

5. How to include dependencies?

First solution is to compile all the sources all the time, so the one file ABC you are compiling contains all the definitions.

Second solution is to compile against ABC libraries but then compile your final program ABC with the libraries ABC into a SWF.

Here you can see a SWF file as a container of multiple ABC.

see How to organise a Redtamarin project.

6. ASC can not use SWC as libraries

You simply can not do the following
$ java -jar asc.jar -import ClassA.swc -import ClassB.swc Program.as
$ java -jar asc.jar -in ClassA.swc -in ClassB.swc Program.as

7. Compiling with Redtamarin.abc

If you need to reuse the Redtamarin APi you will have to compile against the redtamarin.abc.

For example:

import C.stdlib.*;

var HOME:String = getenv( "HOME" );
trace( "HOME = " + HOME );

You will need to compile with the following
$ java -jar asc.jar -import redtamarin.abc Program.as

But then, because the redshell runtime already embed the Redtamarin API you can then directly run your program with $ redshell program.abc (eg. redshell contains and initialise first redtamarin.abc).

7. ASC can compile SWF but with limitations

You do have the option -swf classname,width,height[,fps] = emit a SWF file but it will work only with the *.as files you are compiling, not with the ABC libraries you are importing.

There is no options in ASC that allow you to take different ABC files and merge them together inside one SWF file.

Redbean

As part of the Redtamarin SDK we provide a build tool named redbean.

This tool is here to polish all those rough edges and make compilation easier.

Mainly you have a redbean library with helper functions like
compile(), makeswf(), projector(), shell(), etc.

See the redbean wiki.

Clone this wiki locally