4 Replies Latest reply on Feb 23, 2010 12:47 PM by jimmyoneshot

    Writing to 2 Files At The Same Time From an Application

    jimmyoneshot Level 1

      In my application I have a line of code that writes data to a jpeg file like this:-

       

      var file:File = File.applicationDirectory.resolvePath("assets/images/abcnews.jpg");

       

      That works fine but I want this data to be written to 2 jpeg files abcnews.jpg AND abcnews2.jpg. I've tried this but it doesn't work:-

       

       

      var file:File = File.applicationDirectory.resolvePath("assets/images/abcnews.jpg"; "assets/images/abcnews2.jpg");

       

      Can anyone please help me modify this code or give me idea to edit it so it writes to both these jpgs? Thanks.

        • 1. Re: Writing to 2 Files At The Same Time From an Application
          archemedia Level 4

          Have you tried using 2 diffrent instances of File?

           

          var file1:File = File.applicationDirectory.resolvePath("assets/images/abcnews.jpg);

           

           

          var file2:File = File.applicationDirectory.resolvePath("assets/images/abcnews2.jpg");

           

          Dany

          1 person found this helpful
          • 2. Re: Writing to 2 Files At The Same Time From an Application
            jimmyoneshot Level 1

            Hi again Dany. As you know it's part of the code you hepled me out with. I've actually already tried the following which is what you suggested:-

             

             

             

            switch(myhtml.location)

            {

             

            case "http://abcnews.go.com/":

             

            var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(myhtml) ;

             

            var s:Object = new Bitmap(imageBitmapData);

             

            var jpgEncoder:JPEGEncoder = new JPEGEncoder( 60 );

             

            var ba:ByteArray = jpgEncoder.encode(imageBitmapData);

             

            var filename:String = "mynewpic";

             

            var file:File = File.applicationDirectory.resolvePath("assets/images/abcnews.jpg");

             

            var file2:File = File.applicationDirectory.resolvePath("assets/images/abcnews2.jpg");

             

            var wr:File = new File(file.nativePath);

             

            var stream:FileStream = new FileStream();

            stream.open( wr, FileMode.WRITE);

            stream.writeBytes ( ba, 0, ba.length );

            stream.close();

            myTilelistAArrayCollection.setItemAt({id:

            "ABC News Item", label:"ABC News Test", icon:"assets/images/abcnews.jpg"}, 0);

            myhtml.location =

            "http://news.bbc.co.uk/";

             

            break;

             

            etc

             

            As you know this takes the bitmap snapshot of the abc news website once it's fully loaded into the html component and saves it as the abcnews.jpg. I know this part works as I've actually deleted the abcnews.jpg and re-ran the app and once it's finished running the jpg has been recreated. It's only the abcnews2.jpg that doesn't seem to be getting created but it should be from the above code as far as I can tell

            • 3. Re: Writing to 2 Files At The Same Time From an Application
              jimmyoneshot Level 1

              By the way I've also tried to do it by repeating the whole thing again within the same 'case'. It works but seems a bit inpractical considering I have to do this for around 50 sites in my final app so I'll have to repeat this code over and over and over. Like this:-

               

               

               

              switch(myhtml.location)

              {

               

              case "http://abcnews.go.com/":

               

              var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(myhtml) ;

               

              var s:Object = new Bitmap(imageBitmapData);

               

              var jpgEncoder:JPEGEncoder = new JPEGEncoder( 60 );

               

              var ba:ByteArray = jpgEncoder.encode(imageBitmapData);

               

              var filename:String = "mynewpic";

               

              var file:File = File.applicationDirectory.resolvePath("assets/images/abcnews.jpg");

               

              var wr:File = new File(file.nativePath);

               

              var stream:FileStream = new FileStream();

              stream.open( wr, FileMode.WRITE);

              stream.writeBytes ( ba, 0, ba.length );

              stream.close();

               

               

              var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(myhtml) ;

               

              var s:Object = new Bitmap(imageBitmapData);

               

              var jpgEncoder:JPEGEncoder = new JPEGEncoder( 60 );

               

              var ba:ByteArray = jpgEncoder.encode(imageBitmapData);

               

              var filename:String = "mynewpic";

               

              var file:File = File.applicationDirectory.resolvePath("assets/images/abcnews2.jpg");

               

              var wr:File = new File(file.nativePath);

               

              var stream:FileStream = new FileStream();

              stream.open( wr, FileMode.WRITE);

              stream.writeBytes ( ba, 0, ba.length );

              stream.close();

              myTilelistAArrayCollection.setItemAt({id:

              "ABC News Item", label:"ABC News Test", icon:"assets/images/abcnews2.jpg"}, 0);

              myhtml.location =

              "http://news.bbc.co.uk/";

               

              break;

              • 4. Re: Writing to 2 Files At The Same Time From an Application
                jimmyoneshot Level 1

                Actually I now realize that the above code doesn't work. The abcnews1.jpg is being created but not the abcnews2.jpg. It's bizarre as I've basically repated the same code straight below it just for the other jpg and it should work.