O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Our main function

Now we will create a simple main function in order to test whether everything works as expected.

In this function, we will create our Fridge, create two items, and add them in the fridge. Then we will iterate over our fridge:

class FridgeManager
{
private static var fridge : fridgeManager.Fridge;
public static function main(): Void
{
fridge = new fridgeManager.Fridge();
var myDrink = new fridgeManager.Drink();
myDrink.name = "Benjamin's drink";
var myFood = new fridgeManager.Food();
myFood.name = "Benjamin's food";
fridge.addItem(myDrink);
fridge.addItem(myFood);
//Let's display what's inside the fridge:
for(stored in fridge)
{
trace(stored.name);
}
}
}

Pop quiz—Typedef, interfaces, and Enums

  1. Is it possible for the compiler to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required