beginning of vector background layers. And a whole load of other stuff too
[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 flash.net.URLLoader;
6         import flash.display.LoaderInfo;
7         import flash.events.*;
8         import flash.net.*;
9
10         import net.systemeD.halcyon.Globals;
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
22                 public function Importer(container:*, paint:MapPaint, filenames:Array) {
23                         Globals.vars.root.addDebug("starting importer"); 
24                         Globals.vars.root.addDebug("container is "+container);
25                         Globals.vars.root.addDebug("paint is "+paint);
26                         this.container = container;
27                         this.paint = paint;
28                         this.filenames=filenames;
29
30                         var sp:uint=0;
31                         for each (var fn:String in filenames) {
32                                 Globals.vars.root.addDebug("requesting file "+fn); 
33
34                                 var loader:ExtendedURLLoader = new ExtendedURLLoader();
35                                 loader.info['file']=sp;
36                                 loader.dataFormat=URLLoaderDataFormat.BINARY;
37                                 loader.addEventListener(Event.COMPLETE,                                         fileLoaded);
38                                 loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler);
39                                 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
40                                 loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
41                                 loader.load(new URLRequest(fn));
42                                 sp++;
43                         }
44                 }
45                 
46                 protected function fileLoaded(e:Event):void {
47                         Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
48                         files[e.target.info['file']]=e.target.data;
49                         filesloaded++;
50                         if (filesloaded==filenames.length) { doImport(); }
51                 }
52                 
53                 protected function doImport():void {
54                 }
55
56                 protected function httpStatusHandler( event:HTTPStatusEvent ):void { Globals.vars.root.addDebug("httpstatusevent"); }
57                 protected function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
58                 protected function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
59
60         }
61 }