Convert AS3 code to Haxe. Updated to work on Haxe 3.