2 Replies Latest reply on Sep 25, 2008 10:05 AM by Oliver Goldman

    Copy file to directory

    h_h
      Can someone explain what I'm doing wrong?
      I have a file that I browse for in a dialog popup. After selecting that file, it needs to get copied to the working directory. But the copy function doesn't work however it gets in the Event.COMPLETE function. And yes I have a directory "data" on the desktop. The problem is I only find examples online that replace a source file with a destination file. But that's not what I need.

      private var fileToOpen:File;
      private function browseForOpen( evt:MouseEvent ):void
      {
      fileToOpen = new File();
      fileToOpen.addEventListener(Event.SELECT, browseForOpenSelected);
      fileToOpen.browseForOpen('Select a video', [ new FileFilter("[*.mov; *.flv]", "*.mov;*.flv") ]);
      }
      private function browseForOpenSelected( evt:Event ):void
      {
      fileToOpen = evt.target as File;
      var destination:File = File.desktopDirectory;
      destination = destination.resolvePath( 'data' );

      fileToOpen.copyToAsync(destination, true);
      fileToOpen.addEventListener(Event.COMPLETE, fileCopiedHandler);
      }
      private function fileCopiedHandler(event:Event):void
      {
      trace("Done.");
      }

      With this code the data directory becomes a flv file (without the .flv extension) after the copyToAsync. I need to get the original file being copied inside the data directory.