1

I've been searching for several days now a way to embed a data file, which is in text format, inside an app I'm trying to build in Adobe Flash for Adobe Air (for Android for now). The text file has a lot of data I want to use in my app, so I want to embed it inside the app, so when the app launches I can use it. I've been reading about how to read and write text file in Flash and Adobe Air, but couldn't find a way to add this file to be part of my app. The Adobe Flash Library that is used for saving various assert (File > Import > Import to Library), doesn't support text file (only image, sound, video, and other graphic formats). Is there an other way to add a different (i.e. Text) file to the app?

As a last resort, and to help me proceed with the implementation, I tried manually copying the file to the Android "Documents" folder, and reading it from the app using this:

var myFile:File = File.documentsDirectory.resolvePath("MyText.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(myFile, FileMode.READ);
var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable);

This worked on the PC when testing, but on Android it couldn't find my text file. I placed it in "My Files > Internal storage > Documents" (on Samsung phone). Is there a different "Documents" folder I should use to be found by documentsDirectory.resolvePath() function...

Anyway, as said, this was last resort solution, and much less preferred, because I don't want the users of my app to need to copy internal data files for the app to work, it should be part of the APK... So embedding the text file somehow inside the app is a much better solution, but I couldn't find a way to do that.

Koby.G
  • 73
  • 9

1 Answers1

0

Thanks Organis for your answer, I didn't yet try it but I guess it should work. I found another answer few hours ago, and will share it now, in case someone else encounters this problem.

You could embed a file from the "Publish Settings" dialog, then going into "AIR for Android Setting" (small wrench icon). On the "AIR for Android Setting" under "General" tab, at the bottom there is "Include files". You can click the [+] icon and add any file you want. From the code you can access this file using standard file read method, using URLLoader & URLRequest functions and Event.COMPLETE to get the data when the file finishes loading.

see screenshot here

Koby.G
  • 73
  • 9
  • Ah, indeed. You can pack files into the package this way and they can be loaded at runtime with no security restrictions as they are trusted (because they are protected by package signature). – Organis Apr 25 '18 at 05:13
  • One last comment, after embedding the text file in the app, you can also find it using File.applicationDirectory.resolvePath() and read it using FileStream.open() and FileStream.readUTFBytes() functions (not just with URLLoader & URLRequest functions I wrote above). – Koby.G Apr 26 '18 at 20:51
  • **File** and **FileStream** classes indeed provide sync file operations. However these classes are AIR only, thus I prefer to stick to **URLLoader** for compatibility and testing reasons. – Organis Apr 26 '18 at 21:24