2 Replies Latest reply on Feb 20, 2010 6:24 AM by Priyankagp

    Problems while loading image

    Priyankagp

      Hello Everyone,

       

      I am new to flex development and I am developing simple AIR for reading image file (JPG) from my local machine. I will be displaying this image later on, however, I am unable to read this image. I am using loader class but it is not reading any bytes. Below are the lines of code. I have placed 'test.jpg' in the 'bin-debug' folder of my AIR.

      I have been struggling with this for quite some time and would really appreciate if  someone can help me out.

       

       

       

      var loader:URLLoader = new URLLoader();

       

      var request:URLRequest = new URLRequest("test.jpg");

      loader.load(request);

       

       

      Best Regards,

      Priyanka G.

        • 1. Re: Problems while loading image
          Karthik@Chennai Level 1

          Hi,

          You get the loaded image from the complete event handler below mentioned code

           

          var loader:URLLoader = new URLLoader();

          var request:URLRequest = new URLRequest("test.jpg");

          loader.load(request);

          loader.EventListener(Event.COMPLETE, onComplete);

          loader.addEventListener(IOErrorEvent.IO_ERROR, onInCompleteLoad);

           

           

           

          function onComplete(event:Event):void

          {

           

          var loader1:URLLoader = URLLoader(event.target);

          //loader 1 will have the image

          }

           

          function onInCompleteLoad(event:Event):void

          {

          }

          • 2. Re: Problems while loading image
            Priyankagp Level 1

            Thanks Karthik!!

             

            Can I ask one more question please?

            How can I convert this event data to either ByteArray / DisplayObject? I need to pass it to PDF document using either addImage / addImageStream methods?

             

             

             

             

            Best Regards,

            Priyanka G.