Main and New Functions

Main Function


You must have one, and only one, main() function in every Haxe program. It is the program entry point function. This means that when your program starts executing, the code in the main() function is processed from the beginning, that is, from its first line.

Its syntax is:
public static function main() { }

Note that main() is a static function. Usually, any function called from main() also has to be a static function, see Functions.

New Function


See [http://haxe.org/ref/syntax]] for further information on the new keyword. This is how you create class instances of:
  • any of the standard classes in Haxe, e.g. Array, Date
  • any of the classes in Haxe targets, e.g. flash.display.Shape, java.io.File
  • any classes created by the programmer.

Go to Arrays to look at the example in class Scores where an array of integers named scores is created.

var scores = new Array<Int>();

Note that the parenthesis is placed after the class name, not after the new keyword. There is more information at http://haxe.org/ref/oop about using new in the constructor of a class, which is used in Object Oriented Programming.

Nov 18, 2014 12:21 pm