title: Can Flash/AS3 load external images regardless of Content-Type?
body: <blockquote>
    <p>Disclaimer: I'm not a flash developer
    but I'm trying to solve a flash issue.
    Please don't assume I'm intimately
    familiar with AS or Flash, because I'm
    not.</p>
  </blockquote>
  
  <p>The dilemma I currently have is that I'm hosting a resource that is <code>application/octet-stream</code>. In my Actionscript code, I'm using some library that ( from what I can recall ) does <code>new Image</code> and loads a resource into that object which was created.</p>
  
  <p>There is a method, <code>loadImage(url)</code> which accepts a url and that's where you feed it the path to the image.</p>
  
  <p>I do not have access to the <code>loadImage</code> source code, so I don't know exactly what it does, but the working one loads the image fine because the <code>Content-Type</code> is <code>image/jpeg</code>. The non-working one ( this one I'm trying to fix ) doesn't because of the different <code>Content-Type</code>.</p>
  
  <p>I'm wondering if someone can tell me if I can make the flash basically parse the URI as if it were <code>image/jpeg</code>, regardless of the Content-Type? </p>
  
  <blockquote>
    <p>I do not have access to the source
    code at the moment, but I'm just
    throwing this out there to get input </p>
    
    <p>If need be, I'll try and get some source code tomorrow</p>
  </blockquote>
  
  <p><strong>EDIT:</strong> Ok, I have access to the source now. Here's the part that loads the image:</p>
  
  <pre><code>postcardImage = new Image();
  postcardImage.loadImage(imagePath);
  </code></pre>
  
  <p>I assume that <code>Image</code> the constructor is native to flash/AS, but I haven't been able to google the <code>loadImage</code> method so it must be custom, right?</p>
  
  <p>Or could the Image constructor itself be custom? An extended version of the original <code>Image</code> with <code>loadImage</code> method and such?</p>
  
  <p><strike>Anyways, does anyone know how I can view the source code of <code>loadImage</code>? </strike></p>
  
  <p><strong>EDIT #2</strong>: I did an <code>ack-grep</code> and found the source code for the <code>loadImage</code> method defined in a library:</p>
  
  <pre><code>public class Image extends Sprite {
  
      private var _source:String;
      private var _loader:Loader;
      private var _bmapData:BitmapData;
      private var _loadedBytes:Number;
      private var _totalBytes:Number;
  
      public function Image() {
          trace('IMAGE');
      }
  
      public function loadImage(s:String):void {
          _source = s;
          _loader = new Loader();
          _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
          _loader.contentLoaderInfo.addEventListener(Event.INIT, onLoading);
          _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
          _loader.load(new URLRequest(_source));
  
          function onProgress(e:ProgressEvent):void {
              _loadedBytes = e.target.bytesLoaded;
              dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS));
              if(!_totalBytes) {
                  setTotalBytes(e.target.bytesTotal);
              }
          }
  
          function onLoading(e:Event):void {
              _loader.contentLoaderInfo.removeEventListener(Event.INIT, onLoading);
          }
  
          function onLoaded(e:Event):void {
              _bmapData = e.target.content.bitmapData;
              addChild(e.target.content);
              dispatchEvent(new Event(Event.COMPLETE));
              _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaded);
          }
      }
  
      public function getBmapData():BitmapData {
          return _bmapData;
      }
  
      public function duplicate():Image {
          var dup:Image = new Image();
          dup.addChild(new Bitmap(_bmapData.clone()));
          return dup;
      }
  
      public function getLoadedBytes():Number {
          return _loadedBytes;
      }
  
      private function setTotalBytes(n:Number):void {
          _totalBytes = n;
          dispatchEvent(new Event("TOTALBYTES_SET"));
      }
  
      public function getTotalBytes():Number {
          return _totalBytes;
      }
  
  }   
  </code></pre>
  
  <p>Can anyone offer advice as to how I can do the <code>loadBytes</code> on this? I was thinking of defining a custom method, <code>loadResource</code> or something which can load regardless of Content-Type... or just create an optional parameter in the current <code>load</code> method and inside, branch out based on what was passed.</p>