Posted by BGoulette in SWF Studio V3 on Jul 17 2008, 11:38 am

I'm not sure what I'm doing wrong!

First, I'm downloading an XML file from the internet as a temporary file. If it downloads successfully, I'm copying it to another filename; after that succeeds, I'm attempting to delete the temporary file. I have a callback that tests for delete success, and right now it's just returning "Operation failed%2e" which isn't all that helpful :(

Here's the code I'm using:


private function onReadA (r:Object, c:Object, e:Object):void
{
   // If our temporary file exists, proceed; otherwise, die.
   ssDebug.trace ("onReadA:: success: "+r.success+", result: "+r.result);
         
   if (r.success) {
      ssCore.FileSys.fileExists({path:"startdir://"+CsiFlash.TMP_FILE}, {callback:onReadB});
   }
   else {
      throwErrorMessage();
   }
}
      
private function onReadB (r:Object, c:Object, e:Object):void
{
   ssDebug.trace ("onReadB:: success: "+r.success+", result: "+r.result);
   
   // Copy the temporary file and, when finished, delete it.
   if (r.success) {
      ssCore.FileSys.copyFile({from:"startdir://"+CsiFlash.TMP_FILE, to:"startdir://"+CsiFlash.LOCAL_FILE}, {callback:onFileCopied});
   }
   else {
      throwErrorMessage();
   }
}
      
private function onFileCopied (r:Object, c:Object, e:Object):void
{
   if (r.success) {
      // Now that our files are in order, load the XML.
      csiDataHolder=new CsiDataHolder(CsiFlash.LOCAL_FILE);
            
      csiDataHolder.addEventListener(IOErrorEvent.IO_ERROR, onDataIOError);
      csiDataHolder.addEventListener(ProgressEvent.PROGRESS, onDataProgress);
      csiDataHolder.addEventListener(Event.COMPLETE, onDataComplete);
            
      CsiFlash.csi.preloadBar.scaleX=0.01;
            
      ssDebug.trace ("Delete temp file! Do it!", "#0000FF");
      ssCore.FileSys.deleteFile({path:"startdir://"+CsiFlash.TMP_FILE}, {callback:fileDeleted});
   }
}
      
private function fileDeleted (r:Object, c:Object, e:Object):void
{
   if (r.success) {
      ssDebug.trace ("fileDeleted:: success: "+r.success+", result: "+r.result, "#008000");
   }
   else {
      ssDebug.trace ("Error:: "+e.description, "#FF0000");
   }
}


The file downloads and gets copied appropriately, and honestly I can probably get by like this, but I'm just curious as to what might be causing the delete operation to fail...Thanks for any advice!


Posted by pompeyd in SWF Studio V3 on Jul 18 2008, 08:24 am

Hi stick,

I'm no expert on Windows, but could it be that the file is locked for copying at the time that you call deleteFile?

I've noticed that when using writeToFile, and copyFile in the past, that the callbacks are returned immediately, but, if I watch the Folder where the file is being written to, it can be a few seconds before it appears - or, at least, the callback is returned before the file appears.

It might be worth inserting an interval between the copy and delete operation to give windows chance to release the file after copying before attempting to delete it.

It could be that Windows locks the file while copying it, and the callback is returning to confirm that the instruction to copy has been sent and accepted by Windows, but the actual action requested has still to be carried out by Windows :confused:

Dunno if I am on the right track, but it seems like a logical scenario :rolleyes:

HTH

Paul


Posted by BGoulette in SWF Studio V3 on Jul 18 2008, 08:55 am

Thanks for the advice, Paul -- I'll keep it in mind when I next run into such a scenario, because the client now wants this thing to run as an HTA.

Joy. :rolleyes:

:)