1 package net.systemeD.potlatch2.utils {
3 import net.systemeD.halcyon.Map;
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;
12 public class Importer {
14 protected var connection:Connection; // destination connection for way/node/relations data
15 protected var map:Map; // map being used - used only in Simplify calls
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;
23 public function Importer(connection:Connection, map:Map, filenames:Array, callback:Function, simplify:Boolean) {
24 this.connection = connection;
26 this.filenames=filenames;
27 this.callback=callback;
28 this.simplify=simplify;
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); });
39 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
40 loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
42 loader.load(request.request);
47 protected function fileLoaded(e:Event,filenum:uint):void {
48 trace("loaded file "+filenum);
49 files[filenum]=e.target.data;
51 if (filesloaded==filenames.length) {
52 var action:CompositeUndoableAction = new CompositeUndoableAction("Import layer "+connection.name);
53 doImport(action.push);
54 action.doAction(); // just do it, don't add to undo stack
55 if (callback!=null) { callback(true); }
59 protected function doImport(push:Function):void {
62 protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(false,"You don't have permission to open that file."); }
63 protected function ioErrorHandler( event:IOErrorEvent ):void { callback(false,"The file could not be loaded."); }