2 Replies Latest reply on Jul 23, 2009 5:34 PM by Joe ... Ward

    openAsync read .png, .jpg files

    smoothcustomer

      So I am working on an AIR app that is a continuously looping slideshow. Periodically it needs to load an xml file, and several images from the local hard drive while the slideshow keeps running.

       

      I've found plenty of examples on how to load my xml file and that is working AOK (see code below). The only thing I can not find an example of anywhere, is how to load an image file (jpg, png) in the same manner.

       

       

      XML Load:

       

      public function loadXML()

      {

           var file:File = File.desktopDirectory.resolvePath("data/xml/config.xml");

           var fs:FileStream = new FileStream();

           fs.addEventListener( Event.COMPLETE, handleXMLLoad );

           fs.openAsync( file, FileMode.READ );

      }

       

      private function handleXMLLoad( e:Event ):void

      {

           var fs:FileStream = e.target as FileStream;

           myXML = XML( fs.readUTFBytes( fs.bytesAvailable ) );

      }

       

      - - - - - - - - - - -

       

      PNG Load??

       

       

      public function loadImage()

      {

           var file:File = File.desktopDirectory.resolvePath("data/images/photo.png");

           var fs:FileStream = new FileStream();

           fs.addEventListener( Event.COMPLETE, handleImageLoad );

           fs.openAsync( file, FileMode.READ );

      }

       

      private function handleImageLoad( e:Event ):void

      {

           var fs:FileStream = e.target as FileStream;

         

           // This is the line I have not been able to track down a clear answer on what to do.

           // After the image is loaded, I need to be able to add it to the stage,

           // but I'm not sure how to deal with the fileStream data.

           // Do I use readUTFBytes? Something else?

       

           myImage = fs.readUTFBytes( fs.bytesAvailable ) ;

       

      }

       

       

      Any help would be appreciated.