Use of flash. utils. bytearray class
The bytearray class provides methods and attributes for optimizing reading, writing, and processing binary data.
Bytearray stores byte streams.
Therefore, the stored content is stored in byte format.
Boolean Type, occupies, one byte, eight digits
Double type, which occupies 8 bytes, 8*8 = 64 bits.
Fill in 0 with a few digits, for example, 3.1415926, convert it into a binary form and store it in its array, and then convert it into a byte by 8 digits, occupies a position in bytearray (Note ),
For example:
Bytearr. writedouble (math. Pi );
Trace (bytearr [1]); // 64
Trace (bytearr [2]); // 9
Trace (bytearr [3]); // 33
Trace (bytearr [4]); // 251
Trace (bytearr [5]); // 84
Trace (bytearr [6]); // 68
Trace (bytearr [7]); // 45
Trace (bytearr [8]); // 24
In the output result, for example, 64, which is the 8-bit hexadecimal
Below is a simple example of this class in the API:
package { import flash.display.Sprite; import flash.utils.ByteArray; import flash.errors.EOFError; public class ByteArrayExample extends Sprite { public function ByteArrayExample() { var byteArr:ByteArray = new ByteArray(); byteArr.writeBoolean(false); trace(byteArr.length); // 1 trace(byteArr[0]); // 0 byteArr.writeDouble(Math.PI); trace(byteArr.length); // 9 trace(byteArr[0]); // 0 trace(byteArr[1]); // 64 trace(byteArr[2]); // 9 trace(byteArr[3]); // 33 trace(byteArr[4]); // 251 trace(byteArr[5]); // 84 trace(byteArr[6]); // 68 trace(byteArr[7]); // 45 trace(byteArr[8]); // 24 byteArr.position = 0; try { trace(byteArr.readBoolean() == false); // true } catch(e:EOFError) { trace(e); // EOFError: Error #2030: End of file was encountered. } try { trace(byteArr.readDouble()); // 3.141592653589793 } catch(e:EOFError) { trace(e); // EOFError: Error #2030: End of file was encountered. } try { trace(byteArr.readDouble()); } catch(e:EOFError) { trace(e); // EOFError: Error #2030: End of file was encountered. } } }}