ByteArray length - UInt

I’m just wondering why field “var length:UInt” of ByteArray class is type UInt ? I’m trying to convert some classes from AS3 to haxe and have "if operation "( example if ( data.length >= buffer) , where buffer is Int) . I need to make additional cast every time when do it, but why length is not Int?

I can’t tell you the reasons why, but I can tell you that porting from AS3 is a lot trickier than I expected it to be. There are lots of little design decisions that can lead to subtle problems with a port. The for loops are killer! Especially look out for any place that the AS3 tries to use the value of the for iterator after the loop exits. In haxe, the value of that iterator is not saved when the loop exits.

So use while loops.

AS3:

for(var i:int = 5; i >= 0; i--) {
    //something
}
trace(i);

Haxe:

var i:Int = 5;
while(i >= 0) {
    //something
    
    i--;
}
trace(i);

Yep–that’s exactly what I did. But the as3hx automatic tool didn’t always do this correctly. I learned the hard way.

Pretty much, if you’re porting from AS3, you have to convert every for loop to a while loop or you risk things not working the same way they did in AS3.