You need to embed a file in ActionScript using the [Embed} meta-data tag, but the file type is not supported.
Use the mimeType "application/octet-stream" to embed a file of any type.
When you need to embed a file which is not supported by the [Embed] tag, such as an XML document, you can use the mimeType "application/octet-stream" to embed a file of any type.
For example, the mx model tag allows XML documents to be embedded in a Flex
application, however this is restricted to mxml implementations only. If you need to embed a file (xml in this case) in ActionScript you can do so as in the following example:
package examplesFirst we define a constant of type Class which will reference the embedded file with the [Embed] meta data tag. The Embed tag mimeType parameter is set to "application/octet-stream" (a byte stream) which will allow us to embed the file:
{
import mx.core.ByteArrayAsset;
public final class XMLConfig
{
[Embed("config.xml", mimeType="application/octet-stream")]
private static const Config:Class;
public static function getXMLConfig() : XML
{
var ba:ByteArrayAsset = ByteArrayAsset( new Config() );
var xml:XML = new XML( ba.readUTFBytes( ba.length ) );
return xml;
}
}
}
[Embed("config.xml", mimeType="application/octet-stream")]
private static const Config:Class;
Next we define a static method which returns an XML object (the embedded file). The method creates a ByteArrayAsset and passes new instance of the embedded file class. Then an XML object is instantiated in which the constructor is passed the embedded file as a UTF string:
public static function getXMLConfig() : XMLThe above example demonstrates embedding an XML document in ActionScript, but you can use this technique just as easily to embed a file of any type.
{
var ba:ByteArrayAsset = ByteArrayAsset( new Config() );
var xml:XML = new XML( ba.readUTFBytes( ba.length ) );
return xml;
}