1 Reply Latest reply on Oct 24, 2010 2:34 AM by vabhatia

    browseForSave

    Mykle Sm

      Why First Alert issued. I need to first calls browseForSave

      ...

      var docsDir = air.File.documentsDirectory;

      var fn;

      try

      {

         docsDir.browseForSave("Сохранить файл как...");

          fn = docsDir.addEventListener(air.Event.SELECT, saveData);

      }

      catch (error)

      {

          air.trace("ошибка сохранения:", error.message)

      }

      function saveData(event){

      filename = event.target;

      if (filename.nativePath.substr(filename.nativePath.length - 4, filename.nativePath.length - 1) != '.txt') {

      filename.nativePath = filename.nativePath + '.txt';

      }

      return filename.nativePath;

      }

      alert('11');

      ...

        • 1. Re: browseForSave
          vabhatia Adobe Employee

          Try this

           

          <?xml version="1.0" encoding="utf-8"?>
          <!-- http://blog.flexexamples.com/2008/08/25/saving-files-locally-using-the-filereference-classs-save-method-in-flash-player-10/ -->
          <s:Application name="FileReference_save_test"
                  xmlns:fx="http://ns.adobe.com/mxml/2009"
                  xmlns:s="library://ns.adobe.com/flex/spark"
                  xmlns:mx="library://ns.adobe.com/flex/mx"
                  xmlns:net="flash.net.*"
                  creationComplete="init();">

              <fx:Script>
                  <![CDATA[
                      private function init():void {
                          textArea.text = describeType(FileReference).toXMLString();
                      }

                      private function btn_click(evt:MouseEvent):void {
                          fileReference.save(textArea.text, "describeType.txt");
                      }
                  ]]>
              </fx:Script>

              <fx:Declarations>
                  <net:FileReference id="fileReference" />
              </fx:Declarations>

              <s:Panel id="panel"
                      width="500" height="300"
                      verticalCenter="0" horizontalCenter="0">
                  <s:controlBarContent>
                      <s:Button id="btn"
                              label="Save Text"
                              click="btn_click(event);" />
                  </s:controlBarContent>
                  <s:TextArea id="textArea"
                          editable="true"
                          width="100%"
                          height="100%" />
              </s:Panel>

          </s:Application>

           

          You can also pass the XML object directly to the FileReference class’s save() method.

           

          I hope this helps you.