R – Packaging some files with a Flex/Flash App

actionscriptactionscript-3apache-flexflashsandbox

Is it possible to package a XML file with a Flex app inside the .swf?

With a Silverlight application, you can do this quite easily but you have to do a http request in flash to grab it if you're using flash??

I've been wondering this ever since I did a pretty serious silverlight application and utilized local txt and xml files for settings\data all over the place in it.

And yes I know it can be done with AIR–Don't mention any adobe AIR specific packages PLEASE

Best Answer

You can do this using the "application/octet-stream" type of Embed:

http://flexscript.wordpress.com/2008/08/02/embedding-text-file-into-flex/

The relevant code:

[Bindable]
[Embed(source="MyFile.txt", mimeType="application/octet-stream")]
private var myFileClass:Class;
...
var MyFileByteArray:ByteArrayAsset = ByteArrayAsset(new myFileClass());
var story:String = MyFileByteArray.readUTFBytes(MyFileByteArray.length)
Related Topic