Classpublic class ByteArrayAsset
InheritanceByteArrayAsset Inheritance flash.utils.ByteArray
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:

  [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 Methods
 MethodDefined By
Constructor Detail
public function ByteArrayAsset()

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1