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).
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();
}