Learning Haxe: Part 3: Objects

Learning Haxe

Haxe is a strongly-typed multi-paradigm programming language that also supports cross-platform compiling into many different source and byte-code languages such as ActionScript 3, JavaScript, Java, C++, C#, PHP, Python, Lua, and Node.js.


Haxe is not purely an object-oriented programming language. However, it easily supports the object-oriented programming paradigm through its class and instance functionality.


Haxe works through classes, object blueprints for functionality.

The entry of a project is through its Main class. This may not always literally be named “Main,” but is where code execution should start.

Note: When running Haxe from the command-line, the option “-main” marks which class should be this starting point.

Field Types

Classes have three different types of fields: Variables, Properties, or Methods.


Object can hold variables. By default, these are private to the object and can be referenced through the this keyword.


A property is variable that is public. It is marked as such within the object with the keyword public. It can be accessed outside of the object through dot-notation.


In Haxe, a method is a function that can be accessed outside of an object. Much like variables in this way, functions must use the keyword public to signal that it can be used outside of the object.

Class Instances

Creating a new copy of an object is called a class instance in Haxe. This is done through the function new().

In programming terminology, the new() function is a constructor. This “constructs” a new object.

In Haxe, a new copy of an object is an instance of that class. When the public keyword is used with a new() function (a method), it allows for creating a new object through sending data into the object as arguments to the function.

Public and Private

As noted with the field types variables and methods, they are private by default. A variable or function is not available outside the object unless the specific keyword public is used.

To be used outside the object, a function (method) must be public. This is the same with a variable (property) that is labeled in the same way.