Ported AS3 source to Haxe.

Converted AS3 source to Haxe using as3hx with some manual tweaks here and there