disable caching when using Flash Debug Player
[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 flash.net.URLLoader;
7         import flash.display.LoaderInfo;
8         import flash.events.*;
9         import flash.net.*;
10
11         import net.systemeD.halcyon.Globals;
12
13         public class Importer {
14
15                 protected var container:Object;                         // destination object for way/node/relations data
16                 protected var paint:MapPaint;                           // destination sprite for WayUIs/NodeUIs
17
18                 public var files:Array=[];
19                 protected var filenames:Array;
20                 protected var filesloaded:uint=0;
21                 protected var callback:Function;
22                 protected var simplify:Boolean;
23
24                 public function Importer(container:*, paint:MapPaint, filenames:Array, callback:Function, simplify:Boolean) {
25                         Globals.vars.root.addDebug("starting importer"); 
26                         Globals.vars.root.addDebug("container is "+container);
27                         Globals.vars.root.addDebug("paint is "+paint);
28                         this.container = container;
29                         this.paint = paint;
30                         this.filenames=filenames;
31                         this.callback=callback;
32                         this.simplify=simplify;
33
34                         var sp:uint=0;
35                         for each (var fn:String in filenames) {
36                                 Globals.vars.root.addDebug("requesting file "+fn); 
37
38                                 var request:DebugURLRequest = new DebugURLRequest(fn);
39                                 var loader:ExtendedURLLoader = new ExtendedURLLoader();
40                                 loader.info['file']=sp;
41                                 loader.dataFormat=URLLoaderDataFormat.BINARY;
42                                 loader.addEventListener(Event.COMPLETE,fileLoaded);
43                                 if (callback!=null) {
44                                         loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
45                                         loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
46                                 }
47                                 loader.load(request.request);
48                                 sp++;
49                         }
50                 }
51                 
52                 protected function fileLoaded(e:Event):void {
53                         Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
54                         files[e.target.info['file']]=e.target.data;
55                         filesloaded++;
56                         if (filesloaded==filenames.length) { 
57                                 doImport();
58                                 paint.updateEntityUIs(container.getObjectsByBbox(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b), false, false);
59                                 if (callback!=null) { callback(true); }
60                         }
61                 }
62                 
63                 protected function doImport():void {
64                 }
65
66                 protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(false,"You don't have permission to open that file."); }
67                 protected function ioErrorHandler( event:IOErrorEvent ):void { callback(false,"The file could not be loaded."); }
68
69         }
70 }