Results 1 to 6 of 6
-
May 9th, 2012, 12:43 AM #1
AS3 ByteArray wierd function pairing?
ByteArray has
writeByte(value:int):void
writeShort(value:int):void
but 2 versions of int
writeInt(value:int):void and writeUnsignedInt(value:uint):void
Why so?
-
May 9th, 2012, 01:19 AM #2
It's not two versions of int. One writes an int and the other writes a uint (unsigned int or positive integer). Both are 4 bytes but ints use one bit for the sign. uints can't store negative numbers but can store numbers twice as large as int can. You also have writeDouble and writeFloat for working with floating point numbers.
Proud Montanadian
We tolerate living and breathing. And niches.
Name Brand Watches
Maybe getTimer() or TweenMax is the answer to your problem . . .
-
May 9th, 2012, 01:35 AM #3
-
May 9th, 2012, 02:00 AM #4
My guess would be that, since there is no native byte and short data types in AS3, a method to write them is unnecessary. You can see that writeByte and writeShort accept an int as an argument and simply ignore higher bits beyond their capacity. Additionally, you can simply read a signed byte as an unsigned byte with two's complement so you shouldn't really need methods to specifically write unsigned bytes and shorts. There are readUnsignedByte and readUnsignedShort methods.
Proud Montanadian
We tolerate living and breathing. And niches.
Name Brand Watches
Maybe getTimer() or TweenMax is the answer to your problem . . .
-
May 9th, 2012, 05:42 AM #5
Hello Canadian,
Regarding the writeUnsignedInt() and writeInt()
var i:int = -6;
var b:ByteArray = new ByteArray();
b.writeUnsignedInt(i); // writes 0xFFFFFFFA
b.writeInt(i); // writes 0xFFFFFFFA
Since the bit pattern is same. Why 2 methods?
And any I have 2 read methods so why not have only 1 method like writeUnsignedInt()
-
May 9th, 2012, 12:05 PM #6
I think the C++ semantics for casting between int and uint are the same as the AS3's, so it might just be an alias for convenience. Or an oversight.
The implementation is the same except for the cast, which, like I said, should have the same semantics.
PHP Code:// C++
void ByteArrayObject::writeInt(int value){
write32((uint32_t)value);
}
void ByteArrayObject::writeUnsignedInt(uint32_t value){
write32(value);
}

Reply With Quote


Bookmarks