Skip to content
August 2, 2008 / Shrikant Patil

Embedding text file into flex

There are some situations in which we want to embedd the files either it may text file or any other kind of files into the flex. We know how to embedding the files like  JPEG, GIF, PNG, SWF, Sound, Fonts etc.

Flex also have an option to embed any kind of file at compile time. The trick is with the ‘mimeType‘ option of the [Embedd] tag. while embedding other kind of files like text (or any) we need  to specify ‘application/octet-stream‘ for mimeType option. Here is the sample;

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

Once you embedded the file like the above, the flex considers the file as ByteArrayAsset, and reference
that ByteArrayAsset to the specified variable, in our case, myFileClass variable, so we can access the
embedded file in our application, like below;

var MyFileByteArray:ByteArrayAsset = ByteArrayAsset(new myFileClass());
var story:String = MyFileByteArray.readUTFBytes(MyFileByteArray.length);

The mimeType=”application/octet-stream” option makes all the difference here. It converts the specified
source to Bytes of array.



Leave a Comment
  1. hacyraimi / Nov 25 2009 6:09 pm

    Many of folks talk about this subject but you said really true words.


  1. Embedding text file into flex « Rich Internet Applications

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: