2 Replies Latest reply on May 11, 2009 1:13 PM by twitskull

    Adobe Air copy from CD to hard disk

    twitskull

      Hi,

       

      I would like to copy file from CD to hard disk.

       

      I use

       

      imageFile = File.applicationStorageDirectory.resolvePath("yachtImages/");


      if (!imageFile.exists)
      {
          imageFile.createDirectory();
             
      }
      else
      {
          Alert.show("exists");
      }

       

       

      code above works and creates directory if not present

       

      now lets go to copying

       

      i use browseforopen and get image native path like this

       

      var imageFile:File = File.documentsDirectory;

      var txtFilter:FileFilter = new FileFilter("JPG Images", "*.jpg;*.jpeg");

      imageFile.browseForOpen("Open", [txtFilter]);

      lblFilename.text = "file://" + imageFile.nativePath

       

      But i can not find a way to copy image from cd to hard disk

       

      var currentImage:File = new File();
      currentImage.resolvePath(lblFilename.text);
      currentImage.copyTo(imageFile, true); // show error

       

      ArgumentError: Error #2004: One of the parameters is invalid.
          at Error$/throwError()
          at flash.filesystem::File/set url()
          at flash.filesystem::File()
          at flash.filesystem::File/resolvePath()
          at AddYacht/addImage()[C:\Documents and Settings\User\My Documents\Flex Builder 3\Ohashi\src\yacht.as:296]
          at AddYacht/___AddYacht_Button47_click()[C:\Documents and Settings\User\My Documents\Flex Builder 3\Ohashi\src\AddYacht.mxml:480]

       

       

      Is there any trick to do that? What am I doing wrong?

       

      Thnx guys

        • 1. Re: Adobe Air copy from CD to hard disk
          Muzak Level 3

          You have to listen for a select event when invoking the browseForOpen() method.

          The event will be triggered when the user actually selected a file.

          And if I'm not mistaken, File.browse() may suffice.

           

          private function selectFile():void {
               var imageFile:File = File.documentsDirectory;
               var imgFilter:FileFilter = new FileFilter("JPG Images", "*.jpg;*.jpeg");
               imageFile.addEventListener(Event.SELECT, imageFileSelectHandler);
          
               imageFile.browse([imgFilter]);
          }
          
          
          private function imageFileSelectHandler(event:Event):void {
               var f:File = event.currentTarget as File;
               f.copyTo(File.applicationStorageDirectory.resolvePath("yachtImages/"), true);
          }
          
          
          1 person found this helpful
          • 2. Re: Adobe Air copy from CD to hard disk
            twitskull Level 1

            You rock

             

            But i have another problem. I use this functions browse to add values to datagrid. I also save in datagrid row filename (nativepath).

             

            I need to have id of the last inserted database record first in order to create subfolder. I use sqlite and get last inserted ID and then create directory in folder yachtImages and then I would like to copy all files that are listed in my datagrid in my newly created dir (like yachtImages/1/).

             

            Is that even posible?