start of vector import support
[potlatch2.git] / net / systemeD / potlatch2 / utils / Importer.as
1 package net.systemeD.potlatch2.utils {
2
3         import net.systemeD.halcyon.Map;
4         import net.systemeD.halcyon.ExtendedURLLoader;
5         import flash.display.LoaderInfo;
6         import flash.events.*;
7         import flash.net.*;
8
9         import net.systemeD.halcyon.Globals;
10
11         public class Importer {
12
13                 protected var map:Map;
14                 protected var files:Array=[];
15                 protected var filenames:Array;
16                 protected var filesloaded:uint=0;
17
18                 public function Importer(map:Map, filenames:Array) {
19                         Globals.vars.root.addDebug("starting importer"); 
20                         this.map = map;
21                         this.filenames=filenames;
22
23                         var sp:uint=0;
24                         for each (var fn:String in filenames) {
25                                 Globals.vars.root.addDebug("requesting file "+fn); 
26
27                                 var loader:ExtendedURLLoader = new ExtendedURLLoader();
28                                 loader.info['file']=sp;
29                                 loader.dataFormat=URLLoaderDataFormat.BINARY;
30                                 loader.addEventListener(Event.COMPLETE,                                         fileLoaded,                             false, 0, true);
31                                 loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler,              false, 0, true);
32                                 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler,   false, 0, true);
33                                 loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler,                 false, 0, true);
34                                 loader.load(new URLRequest(fn));
35                                 sp++;
36                         }
37                 }
38                 
39                 protected function fileLoaded(e:Event):void {
40                         Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
41                         files[e.target.info['file']]=e.target.data;
42                         filesloaded++;
43                         if (filesloaded==filenames.length) { doImport(); }
44                 }
45                 
46                 protected function doImport():void { }
47
48                 protected function httpStatusHandler( event:HTTPStatusEvent ):void { }
49                 protected function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
50                 protected function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
51
52         }
53 }