views:

65

answers:

2

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

A: 

You could encode your xml as a string when you compile.

Depending on how you roll your builds, this string could be replaced every time you compile.

jedierikb
+5  A: 

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)
Glenn
exactly what I needed. Still uglier then Silverlight but you can hardly be faulted for that.Thanks
brian
Just out of curiosity, why do you have to do it this way rather than just hard coding it? Either way you have to recompile it if the contents change.
Amarghosh