title: Reading JPG into BitmapData in ActionScript 3 (JPG is inside APK file)
body: <p>I'm using Adobe AIR to make 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", which contains image.jpg.</p>
  
  <p>I'm trying to read that image.jpg into the program at runtime but can't get the location of it (the program doesn't seem to find it.</p>
  
  <p>Here's what I'm trying:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>The onComplete-function puts sets the bitmapData field. However, the COMPLETE event never happens so the while loop never exists.</p>
  
  <p>I have also tried:</p>
  
  <pre><code>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"));
  </code></pre>
  
  <p>None of it works.</p>
  
  <p>I can't get this to work even when trying without the APK file, when only running the SWF file that is generated (the images subfolder is in the same folder as the SWF file).</p>
  
  <p>I can't embed the JPG into the SWF file itself because I need to have a lot of image files and Flash CS6 runs out of memory when making such a big SWF file (reading the images externally would also mean a whole lot less compilation time).</p>
  
  <p>Any ideas? How can I get put the external JPG file into BitmapData? Remember that the image is not outside of the APK file, it is packaged inside it.</p>
  
  <p>Note: I'll also export the thing into a iOS ipa package later so it have to work there as well.</p>
  
  <hr>
  
  <p><strong>Edit because I can't self-answer due to my reputation.</strong></p>
  
  <p>Strille made me realize that the ActionScript Virtual Machine is single-threaded.</p>
  
  <p>So it's impossible to make a thread sleep (wait) for an image being loaded. Instead I have to <em>sigh</em> rewrite a lot of code so that things are halted and continues when the onComplete function is called.</p>
  
  <p>This thing that I tried before actually works but couldn't complete due to the while loop:</p>
  
  <pre><code>loader.load(new URLRequest("app:/images/image.jpg"));
  </code></pre>