title: As3 Convert ByteArray to Bitmap
body: <p>Noob to As3 Bitmap stuff...</p>
  
  <p>when i try to doing the following code it fails</p>
  
  <p>bmd.setPixels(bmd.rect, decodeValue);</p>
  
  <p>and the error message is:
  Error: Error #2030: End of file was encountered.</p>
  
  <p>The situation is i have store the image as binary into the database by convert the byteArray and now i would like to retrieve it and convert back to image.</p>
  
  <p>Just to clear this up ByteArray Need to Place into Bitmap and then you can add to the movie Clip right?</p>
  
  <pre><code>import flash.display.Loader;
  import flash.net.URLRequest;
  import flash.display.Bitmap;
  import flash.display.BitmapData;
  import com.dynamicflash.util.Base64;
  
  var loader:Loader;
  var req:URLRequest;
  var orig_mc:MovieClip;
  var copy_mc:MovieClip;
  
  function loaderCompleteHandler(evt:Event) {
      //swap data
      var ldr:Loader = evt.currentTarget.loader as Loader;
      var origImg:Bitmap = (ldr.content as Bitmap);
      var origBmd:BitmapData = origImg.bitmapData;
      trace(origImg.bitmapData);
      trace(origImg.width);
      trace(origImg.height);
  
      //Convert image byteData into Base64 String 
      var byteArray:ByteArray = new ByteArray();
      byteArray.writeObject(origBmd);
      var encoded:String = Base64.encodeByteArray(byteArray);
      trace("\nENCODED:\n" + encoded);
      var decoded:ByteArray = Base64.decodeToByteArray(encoded);
      trace("\nDECODED:\n" + decoded.toString());
  
      // convert base64 string back into movieclip
      var newBmd:BitmapData = new BitmapData(origImg.width,origImg.height,"true",0xFFFFFFFF);
      newBmd.setPixels(origBmd.rect, decoded);**// THIS THROWS AN " Error #2030: End of file was encountered."** 
      var image:Bitmap = new Bitmap(newBmd, "auto", true);
      copy_mc.addChild(image);
      copy_mc.x = origImg.width;
  }
  
  loader = new Loader();
  req = new URLRequest("C:\\Data\\cutcord.jpg");
  loader.load(req);
  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
  // movieclip to display original image
  orig_mc = new MovieClip();
  orig_mc.addChild(loader);
  addChild(orig_mc);
  // movieclip to display image copy
  copy_mc = new MovieClip();
  addChild(copy_mc);
  
  Anyone can help would be very appreciated :)
  </code></pre>