ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
mx.core 

ByteArrayAsset  - AS3 Flex

Packagemx.core
Classpublic class ByteArrayAsset
InheritanceByteArrayAsset Inheritance ByteArray Inheritance 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
 PropertyDefined By
 InheritedbytesAvailable : 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
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedendian : String
Changes or reads the byte order for the data; either Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN.
ByteArray
 Inheritedlength : uint
The length of the ByteArray object, in bytes.
ByteArray
 InheritedobjectEncoding : 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
 Inheritedposition : uint
Moves, or returns the current position, in bytes, of the file pointer into the ByteArray object.
ByteArray
 Inheritedshareable : Boolean
Specifies whether the underlying memory of the byte array is shareable.
ByteArray
Public Methods
 MethodDefined By
  
Constructor.
ByteArrayAsset
 Inherited
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
 Inherited
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
 Inherited
Clears the contents of the byte array and resets the length and position properties to 0.
ByteArray
 Inherited
compress(algorithm:String):void
Compresses the byte array.
ByteArray
 Inherited
Compresses the byte array using the deflate compression algorithm.
ByteArray
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Decompresses the byte array using the deflate compression algorithm.
ByteArray
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Reads a Boolean value from the byte stream.
ByteArray
 Inherited
Reads a signed byte from the byte stream.
ByteArray
 Inherited
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
 Inherited
Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream.
ByteArray
 Inherited
Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream.
ByteArray
 Inherited
Reads a signed 32-bit integer from the byte stream.
ByteArray
 Inherited
readMultiByte(length:uint, charSet:String):String
Reads a multibyte string of specified length from the byte stream using the specified character set.
ByteArray
 Inherited
Reads an object from the byte array, encoded in AMF serialized format.
ByteArray
 Inherited
Reads a signed 16-bit integer from the byte stream.
ByteArray
 Inherited
Reads an unsigned byte from the byte stream.
ByteArray
 Inherited
Reads an unsigned 32-bit integer from the byte stream.
ByteArray
 Inherited
Reads an unsigned 16-bit integer from the byte stream.
ByteArray
 Inherited
Reads a UTF-8 string from the byte stream.
ByteArray
 Inherited
Reads a sequence of UTF-8 bytes specified by the length parameter from the byte stream and returns a string.
ByteArray
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Provides an overridable method for customizing the JSON encoding of values in an ByteArray object.
ByteArray
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Converts the byte array to a string.
ByteArray
 Inherited
Decompresses the byte array.
ByteArray
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Writes a Boolean value.
ByteArray
 Inherited
Writes a byte to the byte stream.
ByteArray
 Inherited
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
 Inherited
Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream.
ByteArray
 Inherited
Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream.
ByteArray
 Inherited
Writes a 32-bit signed integer to the byte stream.
ByteArray
 Inherited
Writes a multibyte string to the byte stream using the specified character set.
ByteArray
 Inherited
Writes an object into the byte array in AMF serialized format.
ByteArray
 Inherited
Writes a 16-bit integer to the byte stream.
ByteArray
 Inherited
Writes a 32-bit unsigned integer to the byte stream.
ByteArray
 Inherited
Writes a UTF-8 string to the byte stream.
ByteArray
 Inherited
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.