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.

Back to the Future !

(language: Odiya) Khanda pralaya ru khanda pralaya parjyanta : (language : Hindi)Quayamat se Quayamat tak….

Long long ago, there were 5 lions staying in a jungle with their families. A 5000 strong grazing animal population was part of the food chain and there was no problem for sustainability. Lions were on hunting spree when they were hungry; else they were uncles to everybody. Climate was good, no dearth of grass, enough water in the river, many fruits in the trees with lot of monkeys of course!! One day a little bird said to one uncle Lion that two strange animals are coming towards their jungle. They walk on their rear limbs, have no tails, eat anything eatable, stay inside a self-made nest, and use tools to do simple things to very complicated things. They have killed many animals on their way including an elephant by using their strange tools. They use some vocals to communicate. They preserve food for bad weather and use a rolling cart for transportations. I think they are dangerous. They are coming to stay here….for ever. The lion said, “I am the king of this jungle. Don’t you know which protein I eat? Elephant is a weak grass eating animal. Let them come I`ll pounce those walky talkies. I am very cruel when I am hungry. Everybody knows. They are not coming to my jungle but to my empty stomach”.

The lion waited and waited, they didn`t turn up. After few days he became very hungry. He thought those guys ran away to some other place. He saw a big fat immobilized spotted deer and thought for a great dinner instead. It was a trap. The two walky talkies killed him. Similarly they killed all the lions and started living there. With time their population grew. There were no lions, so they were on the top of the food chain. They developed medicines from herbs, used fire for cooking and many new things which surprized other animals. They overwhelmingly killed the grazing animals, even if they were not hungry! After few hundred years, grazing animals reduced to double digits. So they cleaned up jungle for agriculture, domesticated the leftover animals. After few hundred years they required more land for agriculture. A fraction of them migrated to the other side of the river and applied all the techniques they knew from this side of the river. After few hundred years, they started looking differently across the river. After few hundred years they had their own vocal communications, customs and Gods somewhat similar and somewhat different. Each side of the river started treating them as a better species. After few hundred years their number became huge. No more jungle no more grass land remained except the desert. At that point of time, they had two options either to reduce their consumption or to produce more. But they could do neither because they were habituated to live in an expensive way and their resources were limited. So they started begging, then stealing, then robbing each other. But none of them worked. So each side across the river secretly decided to attack the other side. They secretly build up unique war-fares and thought that they had an edge. One stormy night, the war started. All the weapons used. Rest is history.

Somebody said, “We all are born to consume resources”. Consume responsibly to live bit longer.

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”.