haXe, NME, Android, and Flash

I’ve spent the last few days playing around with haXe and nme consumed by the dream of maybe one day compiling to both android and flash.

There have been more than a few issues, but so far I’ve struggled past or through most of them. I wish, though, that I’d written them down, especially since the internet repeatedly failed to present me with solutions.

My motives, however, are primarily selfish in nature. I mean maybe someone, somewhere, may encounter the same issues I did. Honestly though, I know I’ll forget these things within minutes and spend such time searching through old code trying to discover what I’d done. Such alarming, frustrating time.

So if anything comes up during the remainder of today (and possibly tomorrow), I intend to post it here.

Right here.

(A few lines further down.)

1. On my android, Date().now.getTime() was returning the time in milliseconds but rounded to the nearest second, which really messed with my framerate/code.
Solution: Lib.getTimer() returned milliseconds rounded to the nearest millisecond. (import nme.Lib;)


2. Referencing the width and height properties of an object extending nme.display.Sprite caused the program to crash on my android.
Solution: I stopped referencing them.

3. Icons. I looked through the code generating errors, and found some neat stuff. Apparently nme wants three icons (36×36, 48×48, 72×72) when compiling for Android, and checks for those. If there’s no match, and your icon file is in SVG format, it autogenerates them.

This is fine (it’s actually great!), except that the SVGs I’d exported from Adobe Illustrator weren’t working. (I could have tried saving it as 3 different PNGs, but… )

I found a reference to gm2d in the code, but I couldn’t figure out where NME was getting the gm2d lib from. I didn’t have it haxelib installed, but it was getting it from somewhere. So I installed gm2d, and made a quick program to check if and how it displayed the SVG file. It didn’t. (It’s probably worth noting, that I then replaced that code with that from gm2d’s SVN trunk.)

Looking through the gm2d code, it turns out the gradient map was empty. None of the linearGradient elements were in the def block, which (at least in the loadDefs function) is where gm2d seems to look1.
Moving the linearGradient elements or editing the code in gm2d.svg.Svg.hx fixed the issue and the graphic displayed. (the stroke attribute, as outputted by Illustrator, on a rect seemed to crash it as well.)

So that was good and all, but it didn’t help me with the gm2d lib that NME was using. I still don’t know where that is.

At this point I tried to use the three specifically sized icons (PNGs).
It didn’t work right away so I quickly gave up and switched back to the SVG route.

I made a simple image in Illustrator, and exported as SVG and hand-edited the file so that it would work:
– I moved the linearGradients into the def block.
– I wrapped the rects in g blocks2.

And at that point it finally worked! (Though, I think there’s also an issue with at least some gradientTransform matrices.)

4. I remember I had to edit Log.hx (std.haxe.Log). I changed a variable name on line 32 (from something like pos to infos – it looked like a mistake in the file)

That’s it for now. I hope it’s of use to someone, and that that someone is me!

At this point, I feel I should note that despite the issues I’ve encountered I really kind of like the whole haXe+nme thing. It’s really neat!
I completely intent to continue using it.

Your friend,



  1. Brad says:

    Karl says issue 4 was fixed Dec 9! I wonder why it wasn’t in my haXe?

  2. Skial says:


    You likely need the latest nightly build to get the latest fixes. Linux and osx builds can be found here

  3. Brad says:

    Two other notes:

    Using .cacheAsBitmap seemed to prevent the program from working on my android. I didn’t test this extensively.

    Using nme.text.TextField for input: textField.type = TextFieldType.INPUT, not textField.input = TextFieldType.INPUT; as shown here.