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 can find the documentation there: http://api.haxe.org/
array.concat() you can do
- To remove elements from an array you can do
array.splice(pos:Int, len:Int) (return a copy).
- To add null elements (well null on neko, not sure how that work on c++) you can do
array[x] = null.
- Class name must start with an uppercase letter, no trick around that I think.
Only when increasing it I think.
cast is supposed to be a safe cast, so I guess here it’d fail, you can use
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
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?
var n:Number; n.toString()
var n:Float; (n + "")
And lastly, Haxe does not have a strict equality operator?
(null == undefined) = true
(null === undefined) = false
To convert to string you can do
And for the strict equality operator since haxe doesn’t have
undefined it doesn’t need it I guess.
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
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