haXe entry point

Lets get down to coding. The first class of ours in haXe is the main class or the program entry point class. The name of the class may be anything but the point to remember here is the entry point is a static function named main. So the first class of a haXe application looks as below.

package;
class Main {	
	public function new(){
	}
	
	public static function main() {
		trace("Hello haXe !");
		new Main();
	}
}

If you keep a closer look, the main class is not a display object, unlike the typical Flash application. Rather we have a general class here which is saved as “Main.hx” and this class has a method called “main()”. This is typical haXe and thats all we need to compile our program to a SWF.
We can save our compiler parameters in a file named “compile.hxml” or something similar as long as we can refer to it as a build file and having a “.hxml” extension. This file is run by the haxe compiler. In our particular case this file looks as

-swf9 bin/swf/Main.swf
-main Main
-cp src

Here we are defining the target type to be produced from the haXe compiler. Then the program entry class and next is class path.
Running this will produce a SWF named “Main.swf” in the folder “bin/swf/Main.swf”.
Quite straight forward and simplicity at its best.