4 Replies Latest reply on Jun 1, 2012 8:52 PM by Sharon Hanlon

    FileReference.save multiple files with a single mouse click

    Sharon Hanlon Level 1

      I've made a program that allows the user to load multiple image files at once and trim away transparent areas.  I want them to be able to click a Save button once, and have the program save all of the trimmed images.  I don't mind whether the user gets a dialogue box prompting for save location or not (I suppose my preference would be to prompt for location for the first one, then use the same location for subsequent saves).

       

      However, FileReference.save() can only be executed in response to user interaction, and if I queue these saves so one only starts after the previous one completes, I can only save the first image.  The second gives me an error that there has been no user interaction.  As a workaround, I've added a new button that the user can click after each file is saved, to kick off the next one, but making them click 240 times to save that many images is less than ideal.

       

      Is there some way I can set this up so it runs in the browser (only locally) rather than in an AIR app or other projector, and will save the files one after the other?

        • 1. Re: FileReference.save multiple files with a single mouse click
          er453r Level 1

          You can pack all the files in a zip file and save only the zip file

          • 2. Re: FileReference.save multiple files with a single mouse click
            Sharon Hanlon Level 1

            After I load them and the user modifies them, they are bitmaps, not files.  So to do what you're suggesting, I'd still have to save them as individual files before I could zip them.

             

            However, what you're suggesting is just a different workaround, not a solution to the problem.  The end result needs to be lots of individual images, not a zip that I then have to go and manually unzip.

            • 3. Re: FileReference.save multiple files with a single mouse click
              NateScreens Level 1

              This is the way I update images size and save into system without FileReference.

              I hope this help.

               

              MXML:

              <mx:SWFLoader id="swfClass" horizontalCenter="0" verticalCenter="0"/>

               

              Script:

              private var iconSizeArray:Array = new Array(16,29,32,36,48,57,72,114,128,512);

              private function exportIconImage():void

              {

                  var file:File = new File();

                  file.addEventListener(Event.SELECT, file_select);

                  file.browseForDirectory("Choose a Directory");

              }

               

              private function file_select(evt:Event):void

              {

                  File(evt.currentTarget).removeEventListener(Event.SELECT, file_select);

                  var image:ImageSnapshot;

                 

                  for(var i:int = 0; i<iconSizeArray.length; i++)

                  {

                      swfClass.width = iconSizeArray[i];

                      swfClass.height = iconSizeArray[i];

                     

                      image = ImageSnapshot.captureImage(swfClass, 100, new PNGEncoder(), true);

                      var fl:File= new File( evt.currentTarget.nativePath+"/"+currentLinkageName+iconSizeArray[i]+".png");

                      var fs:FileStream = new FileStream();

                      fs.open(fl, FileMode.WRITE);

                      fs.writeBytes(image.data,0,image.data.length);

                      fs.close();

                  }

              }

              • 4. Re: FileReference.save multiple files with a single mouse click
                Sharon Hanlon Level 1

                Thank you.  I remember reading about FileStream - I'll have to look into it again.  Maybe I didn't use it because I got the impression it only runs with AIR - or maybe I read it in relation to something else, then forgot about it afterwards.