| Package | net.guttershark.util |
| Class | public dynamic class BitField |
| Inheritance | BitField flash.utils.Proxy |
Essentially this class allows you to store data in any part of an unsigned integer. This class manages the reading and writing from the unsigned int.
As an example, say you have two flag variables you want to
track, hasPanelBeenRendered and hasXMLLoaded.
Using a bitfield uses 1 unsigned integer internally, to store those
two flags. So say you have this byte. 00000011. The least significant (right-most)
1 represents hasPanelBeenRendered, and the 1 in the 2's spot represents
the hasXMLLoaded flag. So you can setup a bitfield to read and write those
properties like so:
var bf:BitField = new BitField();
bf.addField("hasPanelBeenRendered",1,0); //1 bit, from 0 offset (right side).
bf.addField("hasXMLLoaded",1,1); //1 bit, next bit in sequence (in the 2's spot);
//read and write these props.
bf.hasPanelBeenRendered = 1;
bf.hasXMLLoaded = 1;
So this example is only using 1 unsigned integer internally to the bitfield, which will save on memory. It's pretty nit picky, but every "bit" helps.
| Method | Defined by | ||
|---|---|---|---|
|
BitField(initialFieldValue:uint = 0)
Constructor for BitField instances.
| BitField | ||
|
addField(label:String, bitCount:int, bitOffset:int):void
Add a field.
| BitField | ||
|
dispose():void
Dispose of all internally used variables for managing the bit field.
| BitField | ||
| BitField | () | constructor |
public function BitField(initialFieldValue:uint = 0)Constructor for BitField instances.
ParametersinitialFieldValue:uint (default = 0) — An initial value of the entire field.
|
See also
| addField | () | method |
public function addField(label:String, bitCount:int, bitOffset:int):voidAdd a field.
Parameterslabel:String — The property name you want to use to read and write to the field.
|
|
bitCount:int — The number of bits to use in the internal unsigned integer.
|
|
bitOffset:int — The number of bits from the right. This is an offset for each piece of information
you want in different bytes of the unsigned integer.
|
import net.guttershark.util.BitField;
var bf = new BitField();
bf.addField("isOpen",4,0);
bf.addField("isTest",4,4);
bf.addField("anotherState",1,8);
bf.isOpen = -16;
bf.isTest = 15;
bf.anotherState = 1;
trace(bf.isOpen);
trace(bf.isTest);
trace(bf.anotherState);
| dispose | () | method |
public function dispose():voidDispose of all internally used variables for managing the bit field.