CasaHx – CASA Lib for haXe

April 6th, 2010  |  Published in Uncategorized  |  3 Comments

I’ve mentioned that I was porting CASA Lib for AS3 to haXe in the last blog post. I’m happy to tell you that it is finished and has been uploaded to haxelib.

If you’re not familiar with it, it has a set of display object classes that have build in methods for removing all listeners/all children, and a destroy method that do that all in once. There are also simple tweening classes, layout helper and a huge set of utilities.

I try to make all the classes as cross-target as possible so that you can use it in JS/C++/PHP/Neko (some of them need nme/neash/canvas-nme).

With haXe’s “using” keyword, the utility classes are even sweeter than the AS3 version. Let’s take an example form the official documentation(in AS3):

var people:Array = new Array(	{name: "Aaron", sex: "Male", hair: "Brown"},
				{name: "Linda", sex: "Female", hair: "Blonde"},
				{name: "Katie", sex: "Female", hair: "Brown"},
				{name: "Nikki", sex: "Female", hair: "Blonde"}	);
 
var person:Object = ArrayUtil.getItemByKeys(people, {sex: "Female", hair: "Brown"});
trace(person.name); // Traces "Katie"

Now you can write it in haXe in this way:

using org.casalib.ArrayUtil;
 
var people = [	{name: "Aaron", sex: "Male", hair: "Brown"},
		{name: "Linda", sex: "Female", hair: "Blonde"},
		{name: "Katie", sex: "Female", hair: "Brown"},
		{name: "Nikki", sex: "Female", hair: "Blonde"}	];
 
var person = people.getItemByKeys({sex: "Female", hair: "Brown"});
trace(person.name); // Traces "Katie"

Note that with “using”, auto-completion can also show the added methods (from ArrayUtil, for the above example).

I’ve also typed all the methods. That means, for ArrayUtil.getItemByKeys() with a Array<Point> input, its output will be typed as Point. Nice feature of haXe isn’t it?

PS. Aaron Clinger, the author of CASA Lib, has found me some days ago. He is very nice that may put CasaHx as the official branch of CASA Lib when it is mature enough :)

Tags:

Responses

  1. Tweets that mention CasaHx – CASA Lib for haXe | Andy Li's Blog -- Topsy.com says:

    April 15th, 2010 at 10:09 pm (#)

    [...] This post was mentioned on Twitter by Andy Li. Andy Li said: New blog post: CasaHx – CASA Lib for haXe http://bit.ly/czkbFf [...]

  2. haXe for interactivity/creative coding | Andy Li's Blog says:

    May 6th, 2010 at 12:09 am (#)

    [...] port some of the libraries from different languages or at least to create a haXe binding. I first ported Casa Lib, as CasaHx, with is a big collection of small classes. I’m also working on C++ target of [...]

  3. haXe libraries to get your project started | Andy Li's Blog says:

    September 20th, 2010 at 4:57 pm (#)

    [...] (blog post) HaXe port of CASALib. A collection of utilities. Multi-target. Sometimes I find it a bit [...]

Leave a Response

*