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.

some cool haXe IDE

Well developing in a language without a specific IDE for itself might be too much for a beginner. Fortunately we have some very cool and nice IDEs available for us.
1. FlashDevelop (Based on SciTE)
2. FDT5 (Based on Eclipse)

While both these IDEs are free, FlashDevelop is windows only. But I am surely in love with FlashDevelop. FDT is good but being on Eclipse, it takes up a lot of memory, on the other hand FDT runs on all platforms. So choose your weapons and get ready to haXe it all.

haXe basics

The bare bone basic of haXe language is one must need an Entry point to the Application. This could be any class, but then one must specify the entry point function, which is “main()” , the signature of function looks like

public static function main() {}

Constructors in HAXE are written as “new()” as below

class GameStage
{
 public function new(){}
}

the package declaration ends with a semicolon (unlike any other major laguages, it does not contain curly braces)

package com.saumya.haxe.helloWorld;
class GameStage
{
	public function new() {}
}

If you are extending an display object, then “super” must be called from the constructor. It snot optional, its mandatory.
Every line of code must end with “;” semicolon, again this is mandatory not optional.
Every class file is saved with “.hx” extension.
The haxe compiler file is saved with “.hxml” extension.
The NME compiler file is saved as “.nmml” extension.
A typical “.hxml: file looks as

-swf bin/swf/inTheBigBrain_as3_FP10.swf
-main Main
-swf-header 800:600:30:000000
-cp src

Similarly to compile from NME, you have to create a “.nmml” file.
A typical “.nmml” file description is here.

for compiling a .hxml file, you fire up the following command,

haxe test.hxml

Have a look at the detailed options.

To compile a nmml file, you have to fire up one of these commands. But the very basic is

haxelib run nme test my.nmml flash

The detailed options are here.

Hope that gives you the very basics of the language.

haXe

What is it all about ? Well its all about another language. Not really, if you know ECMA script like javascript or actionscript, haXe is just another home. It does not hurt to learn the simplicity of the language. That does not mean, its not capable! The capability of this language is, it compiles to a lot of platforms! Are you serious?! Yeah, you heard it right. It compiles to almost all the platforms we have now. Starting from AVM1 and AVM2 swfs to native windows, mac, linux applications.
The simplicity of a scripting language and the robustness of C, the best of both worlds! Awesome. For a quick overview of all the platforms, head over to the official page here.
Now haXe comes with a lot of libraries on top of the basic language, which makes it even interesting. And one of the such libraries is NME. After working in NME for a week, I am not kind of addicted to it. It simply allows the code to be compiled to HTML5 and iDevices like iPhone/iPad. The complete list of supported devices are listed here in the official page.
Hope that should already have been making you interested in haXe.

If you still need to see some hands on coding and examples, join me this sunday, where I am doing a workshop on haXe and NME for flash developers.
Happy haXe -ing.

December with a new beginning !

Well, after a continuous month of learning and posting about javascript and canvas, I am up for a new learning. And this time its haXe with NME. Yeah, the excitement is tremendous and I can not explain in words about what I got in last few days. HAXE is truly a life saver in many occasion.
As I will go on on my study of the language and the compiling options I am planning to post it here.
So let the party begin.

It was an exciting travelling time.

After a small travel around the country, meeting old friends, making new friends, visiting old places, going to new places and what not, finally I am back home. So the delay and posting here. Though travelling could not hold me back from posting, but then I took some time off to be back again and posting here.
By the way, thank you all who are visiting it, I must say the amount of crowd I am getting here is really motivating. Please do leave a comment, they are equally valuable to me too :)

My on the move partners, thanks.

Well, lately I am travelling a lot arround India. Most of the time I want to be online and do my job as well of continuous blogging and studying stuffs I like.
I must thank my HTC wildfire phone which runs Android OS, Airtel prepaid with 2g and rooming, my MacBook Pro, and my phone hotspot. These things made me a complete mobile office, productive and fun. Though slow connection but I did almost all of my travel tickets, voice chat over Skype, through these only things.
Love you guys and thank you for supporting me at my need.

Posted from WordPress for Android through my “HTC Wildfire”.

Steve Jobs (1955-2011)

Woke up to a day where the world as a whole lost a visionary, motivator, leader and a true free human being, Steve Jobs.
Could not believe that we friends from all around, were calling each other to convey and grief for the great soul. He made us a family, never with us physically but connected the whole world with his ground breaking products, which definitely has a magical value which each human being has. Thats why probably all of us around the world are somehow related and felt the loss.
I, myself is fortunate enough to live in an age, where I can say proudly, Mr Steve Jobs lived.
Thank you for being with us, thank you for motivating me, thank you for showing how to live till your last breath, thank you for a human being, thank you for believing in magic rather than logic, which is truly human in all the senses. Will miss you for ever.