NME 3.2 is released

This seems to be one of the most active projects. The last beta release and this final release of NME 3.2 is a proof of that.
Well with this release it is now confirmed that NME supports SWF assets to publish to SWF and C++ targets. This is just one of the many advantages one get while using NME.

The new project file improvements are noted here.
Again I am putting the same here for a quick reference.
















Happy haXe -ing

haXe : Conditional compiling

A nice and exciting feature about haXe is conditional compilation. That means one can specify which code to compile depending upon the target chosen at the compile time. Hah, that does not make sense ? Ya, I know. Let me explain again.
There is a compiler and while providing argument to it we have to specify which target we are compiling to. Like in case of haXe and NME we can compile it to a lot of different targets. The compiler argument for flash or swf output looks as below

haxelib run nme test app.nmml flash

Now we can compile the code to HTML5 with the following argument

haxelib run nme test app.nmml html5

Thats the beauty of the language. Most of the time its the same code, but then there are times when we need to write different codes for different targets (may be layout, view elements, can be anything). But then one does not need to keep a separate project for all the different cases. The solution is conditional compiling. What it does is depending upon the target type specified to compiler, it picks up the right code from the same file. Whoaa!! Magic :)
How does it do it or how we make it aware of this ?! You asked it. Lets see it.

#if flash
//Code for SWF output
#elseif js
//Code for HTML5/js output
#else
#end

Thats simple. Its one file, completely in itself, but when it comes to compiler it picks up the right code part depending upon the target type.

One thing to remember though, that when specifying HTML5 target, it picks up conditions from “js”, it does not have a “html5″ option. This particular thing took me sometime to figure out. Just thought would point out here saving someone’s time out there.

Happy haxe -ing :)

haXe : adding image to a project

Well, while its all well and good to create graphics and animations on runtime with code. We must agree that there are situations, when we need to external images in our project. This is done by defining a tag in our .nmml file. The exact thing looks as below.

<assets path="src/assets/" rename="assets/all/" include="*"></assets>

In the tag above we are defining that all the files inside “src/assets” folder will be copied over to our final project under folder “assets/all”. Thats one part of the story. Now in our haXe code, we access the assets with their path as below.

import nme.Assets;//import the Class
var img:Bitmap = new Bitmap (Assets.getBitmapData ("assets/all/home.jpg"));//get the asset

The code above the pretty self explanatory. First we need to import the “nme.Assets” and then use it to get the asset into our project. Things to note, while providing path to access the resource, its the “renamed” path we define in the “XML” while adding the asset.
Happy haXe -ing

haXe : switch-case

This syntax is slightly different from other languages in general. It requires a “default” case and without that the compiler will throw error compiling it. The second change is, we do not need a “break” at each “case”, the “break” is automatically called on the last statement.
The general syntax is

switch (result)
		{
			case 'one':
				i = 1;
				//break;
			case 'two':
				i = 2;
			case 'three':
				i = 3;
			case 'four':
				i = 4;
			case 'five':
				i = 5;
			case 'six':
				i = 6;
			case 'seven':
				i = 7;
			default :
				i = 0 ;
		}

Thats not a very huge change, but I think the information will save you sometime in the beginning.
happy haXe -ing.

haXe : dynamic datatype

It may be surprising to believe that the data types are static in haXe, though typed dynamically! This is awesome, for it gives you freedom to just type a variable without defining its datatype at the same time it will not allow to assign other data types to be assigned to the same variable. The best of both worlds. Whether you come from a dynamic language like javascript or a statically typed language like actionscript 3, this will surprise you in the beginning for sure. Another cool thing (rather hot thing) about haXe is these datatype mismatch will be checked at compile time and if mismatched, will not be compiled! Just beautiful.
Here is an example code.

private function testDataType()
	{
		var a;
		a = 2;
		trace(a);
		a = '2';
		trace(a);
	}

The compiler will throw an error saying “String should be Int”. But how it knew that the datatype is Int ?!! The catch is, when the variable is assigned a value for the first time, the datatype is defined for that variable at that point and there after can not be changed. In our case we defined it as Int when assigned the value for the first time.

This concept goes further to function arguements and return types as well.

private function testDataType(x)
	{
		trace(x);
	}

If we call above function with two different types of data as

testDataType(2);
testDataType('test');

The compiler will trow an error saying data type mismatch.
Lastly if there is a return type example code is as below.

	private function testDataType(x)
	{
		if (x==2)
		{
			return 2;
		}else {
			return 'hello';
		}
	}

Though we can assume to write something like above in a dynamic language, but haXe compiler will not compile this, instead throw an error saying data type mismatch.
Happy haXe -ing. :)

NME 3.1 RC4 is released

Well moving ahead with haXe and NME is as exciting as the new release of NME library. Though this is a minor release to RC4, but looking at the speed of its release cycle, it seems we are just fine learning the new options in NME, where the NME development team is doing their best to give us new features soon.
If you are like me and coding in MAC then there is definitely a point when you think how to install the new libraries into my development environment. Actually its as simple as putting the downloaded library in right folder and setting the current environment to point to the latest version.
It may be required depending upon your machine settings that you may require to configure your machine so as to show all the hidden and system files, which are generally hidden.
All the supporting libraries of haXe, remains inside haXe folder. So just navigate to

/usr/lib/haxe/lib

And there you will find all the library folders.Now go inside “nme” folder and the current version of the library will be present there. All we have to do is, download a new version of the library and put it in this folder. I have recently downloaded the 3.1RC4 and extracted it into this folder. The main folder name I kept as “3,1,RC4″, keep a note these are comma (3,1,RC4) thats how haXe reads them. So its just a practice. Now there is a file inthis folder with name “.current”(This file is generally hidden). Here the currently active version of the lib is specified. Open this file in a text editor and remove everything else (If there is anything at all there). Then type “3.1.RC4″ as the only text in the file. Just remember when we name our folder as comma separated values, haXe reads them as dot(.) while reading from the “.current” file, so we have to just follow this instruction.
That all to it. If you fire up the Terminal in MAC and type

haxelib list

then the output will show something like

nme: 3.0.1 [3.1.RC4]

The version with a square bracket is the currently active version.
So get the latest lib and activate it in development environment and have fun :)

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.