//////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// package mx.core { import flash.utils.ByteArray; /** * 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.