— Shang Liang

Archive
Tag "mistake"

I was trying to read a specific part of a file in AIR. I thought readBytes function in FileStream can serve the purpose but I was wrong.

public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

Reads the number of data bytes, specified by the length parameter, from the file stream, byte stream, or byte array. The bytes are read into the ByteArray objected specified by the bytes parameter, starting at the position specified by offset.

The offset parameter is defined as the offset position in bytes. It defines where to store the data in bytes not where FileStream starts to read. The correct way is to move the FileStream.position and specify the length fo data needed.

Read More