1 Reply Latest reply on Mar 13, 2007 2:34 AM by cgrail

    How to resize dynamically loaded Base64 Image?

    cgrail
      Hi all,

      I'm currently writing a flex component which renders a formular from a
      xml definition file. I get the image as Base64 and decode it whith some
      flex internal methods.

      private function addBgImage(base64Image:String):void{
      var base64Decoder:Base64Decoder = new Base64Decoder();
      base64Decoder.decode(base64Image);
      var byteArray:ByteArray = base64Decoder.flush();
      var loader:Loader = new Loader();
      loader.loadBytes( byteArray );
      var img:Image = new Image();
      img.addChild(loader);
      this.addChild(img);
      }

      This works fine. Now i want to resize the image, but nothing works. I
      tried:

      img.width = 100;
      img.maxWidth = 100;
      img.explicitWidth = 100;
      loader.width = 100;

      But nothing works. Can somebody help me? Do I need to wait till the
      ByteArray is loaded?

      Best regards,
      Christian
        • 1. Re: How to resize dynamically loaded Base64 Image?
          cgrail Level 1
          solved.

          solution:
          I have to wait till the loader finished loading and then i can resize the image in this method.

          private var loader:Loader;
          private function addBgImage(base64Image:String):void{
          var base64Decoder:Base64Decoder = new Base64Decoder();
          base64Decoder.decode(base64Image);
          var byteArray:ByteArray = base64Decoder.flush();
          loader = new Loader();
          loader.loadBytes( byteArray );
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
          var img:Image = new Image();
          img.addChild(loader);
          this.addChild(img);
          }

          private function imgLoaded(event:Event):void{
          loader.width = 100;
          }