I am using Adobe AIR to create an APK file for my Android phone. Inside the APK package there is a SWF file and in the same folder as the SWF file, there is a subfolder named "images" that contains image.jpg.
I am trying to read this image.jpg in a program at runtime, but cannot get its location (the program does not seem to find it.
Here is what I am trying:
var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); loader.load(new URLRequest("images/image.jpg")); while (bitmapData==null) {} //wait until loaded return bitmapData;
The onComplete function puts sets the bitmapData field. However, the COMPLETE event never occurs, so the while loop never exists.
I also tried:
loader.load(new URLRequest("/images/image.jpg")); loader.load(new URLRequest("app:/images/image.jpg")); loader.load(new URLRequest("app-storage:/images/image.jpg")); loader.load(new URLRequest("file:/images/image.jpg"));
None of this works.
I can not get this to work even if I try without an APK file when I run the created SWF file (the subfolder of the images is in the same folder as the SWF file).
I cannot embed JPG in the SWF file itself because I need to have many image files, and Flash CS6 runs out of memory when creating such a large SWF file (reading images from the outside also means much less collection time).
Any ideas? How can I put an external jpg file in BitmapData? Remember that the image is not outside the APK file, it is packed inside it.
Note. I also export the thing to the iOS iOS package later, so it should work there as well.
Change, because I can not answer on my own because of my reputation.
Strille made me realize that the ActionScript virtual machine is single-threaded.
Thus, it is not possible to create a stream (wait) for the uploaded image. Instead, I have to sigh, rewriting a lot of code so that things stop and continue when the onComplete function is called.
This thing I tried before it works, but cannot complete due to the while loop:
loader.load(new URLRequest("app:/images/image.jpg"));