Hi, long time AS3 dev here, and I’m just jumping into Haxe because its faster, better (strongly typed, extension methods, etc) and it holds much more promise than AS3 or ASC2.
I need some help in porting the following Array commands:
array.concat() - typically used to shallow clone an array if called with no arguments, but no longer possible (at least 1 arg needed). How do I shallow clone an array using in-built functions?
array.length = x - used to set the length of an array, deleting extra items or adding nulls to the end. What is the Haxe equivalent?
myClassName - classes no longer allow lowercase names? I really need this as I have dozens of such classes. Any way to override this error? (module name must start with an uppercase letter)
You might also consider using openfl.Vector, which should support the length argument
Yeah, between basic types, you should use something like Std.int to perform conversion. As for other types of casting (like between MySpriteSubClass and Sprite) you can use either cast (myObject, Sprite) for a safe (but slightly slower) cast, or cast myObject to perform an unsafe cast, which has no performance penalty but may crash if it was invalid
Is this the correct way to cast values? This is not exactly casting, its more like a coercing, whereby the value is automatically converted or rounded to match the output type.
AS3 … Haxe
int(5.2) … Std.int(5.2)
Number("5") … Std.parseInt("5")
String(500) … cast(500, String)
And what is the toString equivalent in Haxe? Is this OK? In AS3 everything that inherits from Object supports toString, why doesn’t Haxe have that?
AS3 :var n:Number; n.toString()
Haxe :var n:Float; (n + "")
And lastly, Haxe does not have a strict equality operator?
I would also consider Std.parseFloat if you expect a float value, rather than an integer, as for String casting, Haxe has an automatic toString behavior which be overridden if you define a toString function in your classes, otherwise it uses a default. Generally it’s easiest to do "hello " + world, but if it’s a single value, I use Std.string (value)
Haxe is not dynamic on a number of targets, this is one reason why Haxe C++ beats AS3 so badly in performance testing when it uses static values (but gets much slower in dynamics, AS3 is more optimized there).
An int value has no “toString” value, but the Std.string method is designed to handle both basic types as well as classes