HaXe

I started having a look at using HaXe a couple a days ago since it promises to be quite interesting.

haXe is a powerful modern language with many compelling features. It is aimed at giving developers a tool to create websites & applications in a single unified language.

It’s quite simple to install and if you use FlashDevelop as editor you’re pretty much set. I also took a look at some plugins for Eclipse, but they felt quite unfinished (granted most were still in beta). I tried Eclihx and HXDT.

Some useful info I found:

  • HaXe install dir: C:\Program Files\Motion-Twin\haxe\
  • Setting SWF properties using the HaXe compiler: -swf-header <header> : define SWF header (width:height:fps:color), i.e. “-swf-header 640:480:31:000000”
  • When your Main class is extending Sprite make sure to add it to the display list using: “Lib.current.stage.addChild(this);”
  • A nice tutorial on using SWCs with HaXe

Away3D in HaXe problem

I tried getting Away3D to run using Haxe, but it keeps on throwing an error at run time when I’m calling View3D.render() on every frame:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.utils::Dictionary@157e1c1 to Function.
at MethodInfo-1076()[C:\Projects\HaXe\test03_away3d\src/away3d/haxeutils/HashMap.hx:50]
at away3d.core.utils::CameraVarsStore/reset()[C:\Projects\HaXe\test03_away3d\src/away3d/core/utils/CameraVarsStore.hx:147]
at away3d.containers::Scene3D/update()[C:\Projects\HaXe\test03_away3d\src/away3d/containers/Scene3D.hx:186]
at away3d.containers::Scene3D/onUpdate()[C:\Projects\HaXe\test03_away3d\src/away3d/containers/Scene3D.hx:85]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at away3d.containers::View3D/notifySceneUpdate()[C:\Projects\HaXe\test03_away3d\src/away3d/containers/View3D.hx:334]
at away3d.containers::View3D/render()[C:\Projects\HaXe\test03_away3d\src/away3d/containers/View3D.hx:921]
at com.dare.haxetest.core::Away3DTest/enterFrameHandler()[C:\Projects\HaXe\test03_away3d\src/com/dare/haxetest/core/Away3DTest.hx:222]

From a commit message in SVN it looks like there is a problem with using Dictionaries in HaXe. As the HashMap class still uses a Dictionary this error seems to be happening. I tried converting it to use the Hash class instead of a Dictionary, but that introduced other problems.

HaXe Iterators

Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513
  1. var myHash:Hash&lt;Int&gt; = new Hash();
  2. myHash.set("one", 1);
  3. myHash.set("two", 1);
  4. myHash.set("three", 2);
  5. myHash.set("four", 3);
  6. myHash.set("five", 5);
  7.  
  8. var total:Int = 0;
  9.  
  10. for ( num in myHash.iterator() ) {
  11. total += num;
  12. trace(num + ": " + total);
  13. }

In computer science, an iterator is an object that allows a programmer to traverse through all the elements of a collection, regardless of its specific implementation. An iterator is sometimes called a cursor, especially within the context of a database.
From Wikipedia

In this particular example you don’t need to use .iterator() as the Hash class is iterable, see http://haxe.org/ref/iterators > ‘Iterable Objects’.

NOTE: Use myHash.iterator() (mind the parenthesis) and not myHash.iterator as I’m used to from coding AS3.