It seems like it should be extremely easy to group classes into packages, but I’ve had a hell of a time trying to derive any meaning from the documentation. After much trial and error, I’ve figured out the following minimal example to show how to create and compile a basic package. This example shows two classes, ClassA and ClassB, where the latter instantiates one of the former.
First, create a directory named testpackage, and two files: testpackage/ClassA.as, and testpackage/ClassB.as. In ClassA.as, put the following:
package testpackage { public class ClassA { } }
In ClassB.as, put:
package testpackage { import testpackage.ClassB; public class ClassB { private var a:ClassA; public function ClassB( ) { a = new ClassA( ); } } }
Now, to compile, run the following command in the parent of /testproject:
mxmlc -compiler.source-path=. testpackage/ClassB.as
(Without the -compiler.source-path=. command-line parameter, it won’t search children of the current directory for package source files.) Whew, wasn’t that easy?
Update: Just in case you’re still having trouble, take note that it’s “-compiler.source-path” and not “-compiler.source.path”. The extra dash makes all the difference, as I found out after staring at my own instructions for a considerable amount of time.