actionscript 3 - Finding out when Recursion involving Asynchronous operation finishes -
i have recursive call includes asyn operation (file copy) ..
want find out when recursive call finishes (along asyn operations).
private function copyinto(directorytocopy:file, locationcopyingto:file):void { var directory:array = directorytocopy.getdirectorylisting(); //get list of files in dir each (var f:file in directory) { if (f.isdirectory) copyinto(f, locationcopyingto.resolvepath(f.name)); else { f.copytoasyn(locationcopyingto.resolvepath(f.name), true); f.addeventlistener(event.complete, onfilecopied); } } } function onfilecopied(event){ alert(event.target); // [object file] }
basically needed copy folder structure drive,and folder being copied contains files 100-200mb , take time copy,which blanks out ui , flash player.
, after files copied, want further things(hopefully without blocking ui).
any help?
thanks .
count calls of copytoasync
, use wrapper function docopy
in example.
private var copycount: int = 0; private var iscopying: boolean = false; public function docopy(directorytocopy:file, locationcopyingto:file):void { iscopying = true; try { copyinto((directorytocopy, locationcopyingto); { iscopying = false; } } private function copyinto(directorytocopy:file, locationcopyingto:file):void { var directory:array = directorytocopy.getdirectorylisting(); each (var f:file in directory) { if (f.isdirectory) copyinto(f, locationcopyingto.resolvepath(f.name)); else { copycount++; f.addeventlistener(event.complete, onfilecopied); f.copytoasync(locationcopyingto.resolvepath(f.name), true); } } } function onfilecopied(event: event): void { copycount--; if (copycount == 0 && !iscopying) trace("finished"); }
important: iscopying
flag checks if copyinto
function still running, otherwise run condition copycount == 0
, copying not finished.
Comments
Post a Comment