1 Reply Latest reply on May 17, 2011 8:01 AM by m1kal_

    Use progress bar to track save event of file to a Local File System

    poortip87 Level 1

      Hello!

       

      I am a new Flex builder!  And, I am loving it!   As expected by a newbie, I encountered a problem!    I need to make a Flex application(Creative Extension Builder) used in Photoshop that pops up a file-save dialog and saves file at the chosen location! I just don't seem to strike a suitable solution! My problem is the file dialog. How do I add the event handler to the file dialog "OK" event? If the user selects a location for saving, and clicks Ok, then the progress bar should show the progress of saving!  The files to be saved are simple images, or pdfs. Nothing heavy..!

       

      Fellas, please help me here..!!

       

       

      Cheers! 

        • 1. Re: Use progress bar to track save event of file to a Local File System
          m1kal_ Level 2

          Hello,

           

          Welcome to the Flex Community!

           

          If you want to monitor the progress of a file writing process like that :

           

          [Bindable]

          public var progress:int = 0;

           

          protected function init():void

          {

          var file:File = File.documentsDirectory;

          file = file.resolvePath("test.txt");

          var fileStream:FileStream = new FileStream();

          fileStream.openAsync(file, FileMode.WRITE);

          fileStream.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS, onProgress);

          for(var i:int = 0;i<100000;i++) {

          fileStream.writeUTFBytes("Hello");

          }

          fileStream.close();

          }

           

          protected function onProgress(event:OutputProgressEvent):void

          {

          progress = (1-(event.bytesPending/event.bytesTotal))*100;

          }

           

          - In this exmaple, I'm opening a file called "test.txt" from my "documents" directory.

          - Then I'm adding the listeners in order to get informartion each time some bunch of bytes are written to the file.

          and finally

          - Then I'm writing my data (here a bunch of "Hello")

          - Then I close the file stream

          - In the event handler "onProgress", I calculate a value from bytesPending and bytesTotal (in this case a int value from 0 to 100)

          - Finally you should bind this value to the visual component which is displaying the progress...

           

          Mich

          1 person found this helpful