remove a huge load of pseudo-traces
[potlatch2.git] / net / systemeD / potlatch2 / utils / Importer.as
1 package net.systemeD.potlatch2.utils {
2
3         import net.systemeD.halcyon.MapPaint;
4         import net.systemeD.halcyon.ExtendedURLLoader;
5         import net.systemeD.halcyon.DebugURLRequest;
6     import net.systemeD.halcyon.connection.*;
7         import flash.net.URLLoader;
8         import flash.display.LoaderInfo;
9         import flash.events.*;
10         import flash.net.*;
11
12         public class Importer {
13
14                 protected var container:Object;                         // destination object for way/node/relations data
15                 protected var paint:MapPaint;                           // destination sprite for WayUIs/NodeUIs
16
17                 public var files:Array=[];
18                 protected var filenames:Array;
19                 protected var filesloaded:uint=0;
20                 protected var callback:Function;
21                 protected var simplify:Boolean;
22
23                 public function Importer(container:*, paint:MapPaint, filenames:Array, callback:Function, simplify:Boolean) {
24                         this.container = container;
25                         this.paint = paint;
26                         this.filenames=filenames;
27                         this.callback=callback;
28                         this.simplify=simplify;
29
30                         var sp:uint=0;
31                         for each (var fn:String in filenames) {
32                                 var thissp:uint=sp;             // scope within this block for the URLLoader 'complete' closure
33                                 trace("requesting file "+fn);
34                                 var request:DebugURLRequest = new DebugURLRequest(fn);
35                                 var loader:URLLoader = new URLLoader();
36                                 loader.dataFormat=URLLoaderDataFormat.BINARY;
37                                 loader.addEventListener(Event.COMPLETE,function(e:Event):void { fileLoaded(e,thissp); });
38                                 if (callback!=null) {
39                                         loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
40                                         loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
41                                 }
42                                 loader.load(request.request);
43                                 sp++;
44                         }
45                 }
46                 
47                 protected function fileLoaded(e:Event,filenum:uint):void {
48                         trace("loaded file "+filenum); 
49                         files[filenum]=e.target.data;
50                         filesloaded++;
51                         if (filesloaded==filenames.length) { 
52                                 doImport();
53                                 paint.updateEntityUIs(container.getObjectsByBbox(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b), false, false);
54                                 if (callback!=null) { callback(true); }
55                         }
56                 }
57                 
58                 protected function doImport():void {
59                 }
60
61                 protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(false,"You don't have permission to open that file."); }
62                 protected function ioErrorHandler( event:IOErrorEvent ):void { callback(false,"The file could not be loaded."); }
63
64         }
65 }