mx.core

# ByteArrayAsset - AS3 Flex

Package | mx.core
Class | public class ByteArrayAsset
Inheritance | ByteArrayAsset ByteArray Object
Implements | IFlexAsset

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

ByteArrayAsset is a subclass of the flash.utils.ByteArray class which represents an arbitrary sequence of byte data that you embed in a Flex application.

The byte data that you are embedding can be in any kind of file, and the entire file is always embedded. You cannot embed the bytes of a particular asset that is in a SWF file, although you can embed an entire SWF file.

The MXML compiler autogenerates a class that extends ByteArrayAsset to represent the embedded data.

To embed an arbitrary file, you declare a variable of type Class, and put `[Embed]` metadata on it, using the MIME type `application/octet-stream`. For example, you embed a text file like this:

      [Bindable]
      [Embed(source="Story.txt", mimeType="application/octet-stream")]
      private var storyClass:Class;

The compiler autogenerates a subclass of the ByteArrayAsset class and sets your variable to be a reference to this autogenerated class. You can then use this class reference to create instances of the ByteArrayAsset using the `new` operator, and you can extract information from the byte array using methods of the ByteArray class:

      var storyByteArray:ByteArrayAsset = ByteArrayAsset(new storyClass());
      var story:String = storyByteArray.readUTFBytes(storyByteArray.length);

You must specify that the MIME type for the embedding is `application/octet-stream`, which causes the byte data to be embedded "as is", with no interpretation. It also causes the autogenerated class to extend ByteArrayAsset rather than another asset class.

For example, if you embed a PNG file without specifying this MIME type, the PNG data will be automatically transcoded into the bitmap format used by the player, and a subclass of BitmapAsset will be autogenerated to represent it. But if you specify the MIME type as `application/octet-stream`, then no transcoding will occur, the PNG data will be embedded as is, and the autogenerated class will extend ByteArrayAsset.

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | bytesAvailable : uint [read-only] The number of bytes of data available for reading from the current position in the byte array to the end of the array. | ByteArray
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | endian : String Changes or reads the byte order for the data; either Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN. | ByteArray
|  | length : uint The length of the ByteArray object, in bytes. | ByteArray
|  | objectEncoding : uint Used to determine whether the ActionScript 3.0, ActionScript 2.0, or ActionScript 1.0 format should be used when writing to, or reading from, a ByteArray instance. | ByteArray
|  | position : uint Moves, or returns the current position, in bytes, of the file pointer into the ByteArray object. | ByteArray
|  | shareable : Boolean Specifies whether the underlying memory of the byte array is shareable. | ByteArray

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | ByteArrayAsset() Constructor. | ByteArrayAsset
|  | atomicCompareAndSwapIntAt(byteIndex:int, expectedValue:int, newValue:int):int In a single atomic operation, compares an integer value in this byte array with another integer value and, if they match, swaps those bytes with another value. | ByteArray
|  | atomicCompareAndSwapLength(expectedLength:int, newLength:int):int In a single atomic operation, compares this byte array's length with a provided value and, if they match, changes the length of this byte array. | ByteArray
|  | clear():void Clears the contents of the byte array and resets the length and position properties to 0. | ByteArray
|  | compress(algorithm:String):void Compresses the byte array. | ByteArray
|  | deflate():void Compresses the byte array using the deflate compression algorithm. | ByteArray
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | inflate():void Decompresses the byte array using the deflate compression algorithm. | ByteArray
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | readBoolean():Boolean Reads a Boolean value from the byte stream. | ByteArray
|  | readByte():int Reads a signed byte from the byte stream. | ByteArray
|  | readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void Reads the number of data bytes, specified by the length parameter, from the byte stream. | ByteArray
|  | readDouble():Number Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream. | ByteArray
|  | readFloat():Number Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream. | ByteArray
|  | readInt():int Reads a signed 32-bit integer from the byte stream. | ByteArray
|  | readMultiByte(length:uint, charSet:String):String Reads a multibyte string of specified length from the byte stream using the specified character set. | ByteArray
|  | readObject():* Reads an object from the byte array, encoded in AMF serialized format. | ByteArray
|  | readShort():int Reads a signed 16-bit integer from the byte stream. | ByteArray
|  | readUnsignedByte():uint Reads an unsigned byte from the byte stream. | ByteArray
|  | readUnsignedInt():uint Reads an unsigned 32-bit integer from the byte stream. | ByteArray
|  | readUnsignedShort():uint Reads an unsigned 16-bit integer from the byte stream. | ByteArray
|  | readUTF():String Reads a UTF-8 string from the byte stream. | ByteArray
|  | readUTFBytes(length:uint):String Reads a sequence of UTF-8 bytes specified by the length parameter from the byte stream and returns a string. | ByteArray
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toJSON(k:String):* Provides an overridable method for customizing the JSON encoding of values in an ByteArray object. | ByteArray
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Converts the byte array to a string. | ByteArray
|  | uncompress(algorithm:String):void Decompresses the byte array. | ByteArray
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | writeBoolean(value:Boolean):void Writes a Boolean value. | ByteArray
|  | writeByte(value:int):void Writes a byte to the byte stream. | ByteArray
|  | writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void Writes a sequence of length bytes from the specified byte array, bytes, starting offset(zero-based index) bytes into the byte stream. | ByteArray
|  | writeDouble(value:Number):void Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream. | ByteArray
|  | writeFloat(value:Number):void Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream. | ByteArray
|  | writeInt(value:int):void Writes a 32-bit signed integer to the byte stream. | ByteArray
|  | writeMultiByte(value:String, charSet:String):void Writes a multibyte string to the byte stream using the specified character set. | ByteArray
|  | writeObject(object:*):void Writes an object into the byte array in AMF serialized format. | ByteArray
|  | writeShort(value:int):void Writes a 16-bit integer to the byte stream. | ByteArray
|  | writeUnsignedInt(value:uint):void Writes a 32-bit unsigned integer to the byte stream. | ByteArray
|  | writeUTF(value:String):void Writes a UTF-8 string to the byte stream. | ByteArray
|  | writeUTFBytes(value:String):void Writes a UTF-8 string to the byte stream. | ByteArray

Constructor Detail

### ByteArrayAsset

()
Constructor

`public function ByteArrayAsset()`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Constructor.

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00