haXe : raytrace v2.0.0

This started of as my own little utility but then I use it in almost all the flash, flex, haXe applications when output is SWF. Now its available as a opensource project in github and the final compile dfiles are here, if you just want to use it.
This is nothing more than a logger named raytrace. It takes string as the only parameter and the implementation is done in haXe and NME.
Just put the “raytrace.as” in the root folder of your flash/flex application and then from anywhere in your code one can write

raytrace('my message');

Then this message will be visible in this RayTrace swf. Both the “.as” file and the “.swf” are packaged here as a zip file for your no time getting started.

Happy haXe -ing

RayTrace : An external logger for flash

Well, with my moving forward with haXe and NME, I needed an external logger for flash targets. Though there is a trace message view by default in haXe, it is necessary to have an external logger for me. RayTrace is written in haXe and can be used in any flash and flex based applications not only written in haXe. So if you are doing a pur actionscript or flex project, still you can use RayTrace as your logger. It comes with a client class for flash based projects, which is written in actionscript. Just put the file in the root directory and you are good to go. From anywhere in your actionscript code do a raytrace as below.

raytrace('my message');

The message you send from your code will be visible in the RayTrace logger. Currently it simply supports the string message only.

The source code is available in github as well so as if you want can go ahead and write your own implementation.

happy haXe -ing

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 :)

NME 3.2 Beta is here

This is another exciting release of NME. And with this comes the support of SWF directly. Though its only for creating SWF and C++ targets but thats huge (Windows, Mac, Linux, Android, iOS, webOS), only thing not present is HTML5.

Now I am waiting to get my hands dirty with the new version.

The official blog entry.
A tutorial for the SWF support.

Happy haXe -ing :)

Happy new year 2012

A very happy new year to all of you.

As you can see I am posting this late, its not intentional but the new year really brought on a lot of energy, surprises and happenings with it from day one. While the year 2011 ended with a big surprise as, meeting a long time online friend Stephanie along with her parents in person. The new year started with a travel to other part of the country and back. My first flight of the year is on the 1st morning. The travel started right in the very early morning. Where there is generally no chance of getting a rickshaw to the airport, I got it right across the lonely road in the middle of the night, a welcoming new year gesture of 2012 I hope. Then the very next day, got some pending money back from my old employer! ahh, nothing like it. Met some old friends and spent quite a quality time. All in all it is a good beginning. Hope it will go on like this for me and for you all.

Cut down the negativity and move on with all your positive spirits, things are bound to happen.

With that wishing you all a very happy and prosperous new year ahead.

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