1 Reply Latest reply on Mar 9, 2008 7:30 AM by Starlover_jacob

    debug crash after base64encode tostring

    Starlover_jacob Level 1
      Hi there, my debugger crashes on the following line:
      var b64String:String = b64encoder.toString();
      also on this line:
      var b64String:String = b64encoder.flush();

      what i try to do is figure out how to convert an image to base64 and back again.
      my code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication creationComplete="initApp()" xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      import mx.utils.Base64Decoder;
      import mx.utils.Base64Encoder;
      import flash.display.BitmapData;
      private var myloader:Loader;
      public function clicktogetphoto():void
      // image to base64 and back to image
      // original image
      var bmpData:BitmapData = new BitmapData( myimage.width, myimage.height, false, 0xe4e4e4 ) ;
      bmpData.draw( myimage,null,null,null,null,true ) ;

      // to bytearray
      var fullpixels:ByteArray = bmpData.getPixels( new Rectangle(0,0,bmpData.width,bmpData.height) );

      // to base64
      var b64encoder:Base64Encoder = new Base64Encoder();
      var b64String:String = b64encoder.toString();

      // decode from base 64
      var base64decode:Base64Decoder= new Base64Decoder();
      var decodedstring:ByteArray=base64decode.toByteArray();

      myloader= new Loader();
      myloader.contentLoaderInfo.addEventListener (Event.COMPLETE, onConvertFinished);
      public function onConvertFinished(evt:Event):void

      <mx:Image id="myimage" source="assets/image.png" x="0" y="0"/>
      <mx:Button id="mybuttonGetphoto" click="clicktogetphoto()" label="getphoto" x="404" y="416"/>
      <mx:Image x="501" y="0" id="mynewloadedimage1" width="340" height="287"/>

      please some help.