Well, I see that this has been solved by others before. A very slight delay (actually a timer of 0 milliseconds!) is all that’s needed before the delete function to make this problem go away.
Interestingly, if the timer is left out of the wait() function and deleteIt() is called from there instead, the problem returns.
import flash.filesystem.*;
import flash.net.URLLoader;
var json:URLLoader
function loadMyJSONData():void
{
json = new URLLoader();
json.addEventListener(Event.COMPLETE, wait);
json.load(new URLRequest("jsondata.json"));
}
function wait(e)
{
var timer:Timer = new Timer(0, 1);
timer.addEventListener(TimerEvent.TIMER, deleteIt);
timer.start();
//deleteIt();
}
function deleteIt(e)
{
var fileToDelete:File = new File();
fileToDelete.nativePath = "C:\\AIR Test 2";
fileToDelete = fileToDelete.resolvePath("jsondata.json");
fileToDelete.deleteFile();
}