views:

2444

answers:

4

I have a tiny actionscript "project" consisting of two files, call them foo.as and bar.as. For reasons I won't go into, I really really want to build the .SWF from the command line, without setting up a formal project of any kind. Every compiler I've ever used lets you do this, but for the life of me I can't figure out how to coerce MXMLC into compiling these two files and linking them into a SWF.

Naively, I try

MXMLC foo.as bar.as

but I'm informed that only one source file is allowed.

Ok, supposing I compiled these two files separately, how would I link them together to get the final SWF?

NOTE: The only reason I have two files instead of one is the requirement of only one class per file. I tried putting both classes in one file and making one of the classes "private" or "internal" but neither of these ideas worked. I would be ecstatic to find out I can put more than one class in a file (with only one being public).

+2  A: 

If the main file/class needs/uses the class of the other file, the other file will also be compiled into the swf.

Hippo
+1  A: 

As Hippo says, the compiler will automatically compile into the SWF all the classes used through your code, it's recursive by default.

You can read also all the options the MXMLC compiler has.

Zárate
+9  A: 

This is a two part question, so I will answer both separately.

Compiling two class files into one SWF

MXMLC will automagiclly compile all classes it finds from the entry point you give it (your main class). It finds classes from your import statements, and full class path definitions.

Here is a really good guide for using MXMLC command line to compile your AS3 projects. The article is a bit dated, but the information is still good. He goes into detail about the things you need to know when using the command line compiler, including the MXMLC options, writing BAT scripts, and a bit about AS3 that you can probably skip if you know what your doing.

Having more than one class in a file

AS3 allows you to have one class per file, plus as much "helper" classes as you like. It does not support protected and private classes like Java does. Helper classes are only visible in the file they are defined.

Helper classes sit outside the package declaration (which is a little weird to me). Here is an example:

package com.mynamespace
{
     public class Foo 
     {
          private var _fooHelper:FooHelper = new FooHelper();
     }
}

// helper class imports also go outside the package.
import com.example.xml.SaxHandler;
class FooHelper
{
     private var bar:Number = Math.random();
}
TandemAdam
A: 

If you're interested in automating that process, you can also use Project Sprouts which includes quite a bit more than you're asking for - but does give you the ability to kick off builds and test runs from the terminal.

Luke Bayes