Array access is not allowed on openfl.utils.ByteArray


When i try to do this “if(messageBytes.length>255 && messageBytes[0] !=4)” i get the compile error complaining about array access not allowed.

Is this not possible in haxe/openfl? Do i need to do something like change the position and use the read methods?


Accessing ByteArrays with array access operator is not possible on JavaScript target for now.

It used to generate array access expression silently on JavaScript target even though it didn’t work. I thought that it just makes finding errors difficult, so I disabled it in this commit and sent pull request.

For now you can access ByteArray with __get() on non-Flash targets, or any other methods available in ByteArray class. It would be better to create inline utility function that allows you to access ByteArray, if you need Flash target.

I hope this to be fixed in future release.

Yeah, there were getter/setter methods that I thought worked across multiple platforms, until I realized that it was C++ only. We need to extend either a native data type in JavaScript that supports array access (like an array or typed array) or be a Haxe abstract, but I don’t think that ByteArray is a good idea to be abstract, because you could not on it, etc.

Open to ideas, the other workaround is setting the position then using readByte