Support importing the <create> element only of <osmChange> files
[potlatch2.git] / net / systemeD / potlatch2 / utils / Importer.as
index c664530dfcd25c5d2dc18768758f4709533c7450..665e627f9d374921f94fc83f6bfae6611ffaa48d 100644 (file)
@@ -2,7 +2,6 @@ package net.systemeD.potlatch2.utils {
 
        import net.systemeD.halcyon.Map;
        import net.systemeD.halcyon.ExtendedURLLoader;
-       import net.systemeD.halcyon.DebugURLRequest;
     import net.systemeD.halcyon.connection.*;
        import flash.net.URLLoader;
        import flash.display.LoaderInfo;
@@ -27,27 +26,25 @@ package net.systemeD.potlatch2.utils {
                        this.callback=callback;
                        this.simplify=simplify;
 
-                       var sp:uint=0;
-                       for each (var fn:String in filenames) {
-                               var thissp:uint=sp;             // scope within this block for the URLLoader 'complete' closure
-                               trace("requesting file "+fn);
-                               var request:DebugURLRequest = new DebugURLRequest(fn);
+                       // Use forEach to avoid closure problem (http://stackoverflow.com/questions/422784/how-to-fix-closure-problem-in-actionscript-3-as3#3971784)
+                       filenames.forEach(function(fn:String, index:int, array:Array):void {
+                               trace("requesting file "+index);
+                               var request:URLRequest = new URLRequest(fn);
                                var loader:URLLoader = new URLLoader();
                                loader.dataFormat=URLLoaderDataFormat.BINARY;
-                               loader.addEventListener(Event.COMPLETE,function(e:Event):void { fileLoaded(e,thissp); });
+                               loader.addEventListener(Event.COMPLETE,function(e:Event):void { fileLoaded(e,index); });
                                if (callback!=null) {
                                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
                                        loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
                                }
-                               loader.load(request.request);
-                               sp++;
-                       }
+                               loader.load(request);
+                       });
                }
                
                protected function fileLoaded(e:Event,filenum:uint):void {
-                       trace("loaded file "+filenum); 
                        files[filenum]=e.target.data;
                        filesloaded++;
+                       trace("loaded file "+filenum+" ("+filesloaded+"/"+filenames.length+")"); 
                        if (filesloaded==filenames.length) {
                 var action:CompositeUndoableAction = new CompositeUndoableAction("Import layer "+connection.name);
                                doImport(action.push);