Merge branch 'localfile'
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 15:24:09 +0000 (16:24 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 15:24:09 +0000 (16:24 +0100)
23 files changed:
l10n/map/LocalizationMap.mxml
net/systemeD/halcyon/DebugURLRequest.as [deleted file]
net/systemeD/halcyon/FileBank.as [new file with mode: 0755]
net/systemeD/halcyon/ImageBank.as [deleted file]
net/systemeD/halcyon/MarkerUI.as
net/systemeD/halcyon/NestedXMLLoader.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/halcyon/styleparser/NestedCSSLoader.as
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/halcyon/styleparser/StyleChooser.as
net/systemeD/potlatch2/CustomLocaleCommand.as [new file with mode: 0644]
net/systemeD/potlatch2/Preloader.as
net/systemeD/potlatch2/collections/Imagery.as
net/systemeD/potlatch2/collections/Stylesheets.as
net/systemeD/potlatch2/collections/VectorBackgrounds.as
net/systemeD/potlatch2/mapfeatures/Feature.as
net/systemeD/potlatch2/mapfeatures/MapFeatures.as
net/systemeD/potlatch2/mapfeatures/editors/Choice.as
net/systemeD/potlatch2/mapfeatures/editors/ChoiceEditorFactory.as
net/systemeD/potlatch2/utils/CachedDataLoader.as [deleted file]
potlatch2.mxml

index 08e5ce942cda63f89bf481dbb1a817560476b2fd..c96738c0f9a0e37b31cbc97184ba345c61401bb6 100644 (file)
@@ -7,7 +7,7 @@
   <!-- Support for Locale ResourceBundle changes -->
   <mx:Script>
     <![CDATA[
-      import org.babelfx.commands.ExternalLocaleCommand;
+      import net.systemeD.potlatch2.CustomLocaleCommand;
       import org.babelfx.events.LocaleEvent;
       import mx.resources.ResourceManager;
       import mx.resources.IResourceManager;
@@ -46,9 +46,9 @@
   </mx:Script>
 
   <commandFactory>
-    <factory:ClassFactory generator="{ExternalLocaleCommand}">
+    <factory:ClassFactory generator="{CustomLocaleCommand}">
       <factory:properties>
-        <mx:Object externalPath="locales/\{0\}.swf"/>
+        <mx:Object defaultExternalPath="locales/\{0\}.swf"/>
       </factory:properties>
     </factory:ClassFactory>
   </commandFactory>
diff --git a/net/systemeD/halcyon/DebugURLRequest.as b/net/systemeD/halcyon/DebugURLRequest.as
deleted file mode 100644 (file)
index 7bbf018..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-package net.systemeD.halcyon {
-
-       import flash.net.URLRequest;
-       import flash.net.URLRequestMethod;
-       import flash.system.Capabilities;
-       import net.systemeD.halcyon.Globals;
-
-    /**
-    * If nocache has been set to 'true' via FlashVars, this will make the URLRequest using
-    * POST rather than GET - thereby preventing FP from caching it.
-    *
-    * <p>Sadly we can't just subclass URLRequest, which is defined as final. So you need to create your
-    * new DebugURLRequest, then refer to its .request property.</p>
-    *
-    * <p>We use an evil Global because we don't know where loaderInfo.parameters will be.</p>
-    *
-    * @see http://www.ultrashock.com/forums/actionscript/force-reload-files-only-using-as3-123408.html
-    */
-
-       public class DebugURLRequest {
-
-               public var request:URLRequest;
-
-               public function DebugURLRequest(url:String=null) {
-                       request=new URLRequest(url);
-                       if (Globals.vars.hasOwnProperty('nocache') && Globals.vars.nocache) {
-                               request.method=URLRequestMethod.POST;
-                               request.data=true;
-                       }
-               }
-
-       }
-
-}
diff --git a/net/systemeD/halcyon/FileBank.as b/net/systemeD/halcyon/FileBank.as
new file mode 100755 (executable)
index 0000000..c79e2ba
--- /dev/null
@@ -0,0 +1,261 @@
+package net.systemeD.halcyon {
+    import flash.events.*;
+       import flash.display.*;
+       import flash.net.*;
+       import flash.utils.ByteArray;
+       import nochump.util.zip.*;
+
+       /*
+               FileBank stores and retrieves bitmap images and other files.
+               Images are internally stored as Loader. Other files are stored as strings.
+
+               See blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/ for a really useful conversion guide!
+       */
+
+    public class FileBank extends EventDispatcher{
+               private var files:Object={};
+               private var filesRequested:uint=0;
+               private var filesReceived:uint=0;
+               private var zipsRequested:uint=0;
+               private var zipsReceived:uint=0;
+        private var zipCallbacks:Array=[];
+               
+               public static const FILES_LOADED:String="filesLoaded";
+               
+               private static const GLOBAL_INSTANCE:FileBank = new FileBank();
+               public static function getInstance():FileBank { return GLOBAL_INSTANCE; }
+
+               public function hasFile(name:String):Boolean {
+                       if (files[name]) return true;
+                       return false;
+               }
+
+        public function fileLoaded(name:String, callback:Function):Boolean {
+            var loaded:Boolean = false;
+            if (files[name]) {
+                if (files[name].info.callbacks) {
+                    files[name].info.callbacks.push(callback);
+                } else {
+                    loaded = true;
+                }
+            }
+            return loaded;
+        }
+
+        /* ==========================================================================================
+                  Add an individual file to bank (not from a .zip file)
+                  Used when we want to load a file for use later on (e.g. an image referenced in a stylesheet)
+                  ========================================================================================== */
+
+               public function addFromFile(filename:String, callback:Function = null):void {
+            if (files[filename]) {
+                if (callback != null) {
+                    if (files[filename].info.callbacks) {
+                        files[filename].info.callbacks.push(callback);
+                    } else {
+                        callback(this, filename);
+                    }
+                }
+            } else if (zipsRequested > zipsReceived) {
+                zipCallbacks.push(function ():void {
+                    addFromFile(filename, callback);
+                });
+            } else {
+                var request:URLRequest = new URLRequest(filename);
+                var loader:Object;
+                var loaderInfo:EventDispatcher;
+                
+                if (isImageType(filename)) {
+                    loader = new ExtendedLoader();
+                    loaderInfo = loader.contentLoaderInfo;
+                    loaderInfo.addEventListener(Event.COMPLETE, loadedImage);
+                } else {
+                    loader = loaderInfo = new ExtendedURLLoader();
+                    loaderInfo.addEventListener(Event.COMPLETE, loadedFile);
+                }
+
+                loader.info.filename = filename;
+                loader.info.callbacks = new Array();
+                
+                if (callback != null) {
+                    loader.info.callbacks.push(callback);
+                }
+
+                files[filename] = loader;
+
+                loaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
+                loaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
+                loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
+
+                filesRequested++;
+
+                loader.load(request);
+            }
+               }
+
+        public function onFilesLoaded(callback:Function):void {
+            if (filesRequested > filesReceived) {
+                addEventListener(FileBank.FILES_LOADED, function(e:Event):void {
+                    callback();
+                });
+            } else {
+                callback();
+            }
+        }
+
+        private function loadedImage(event:Event):void {
+                       fileLoadComplete(event.target.loader.info);
+        }
+        private function loadedFile(event:Event):void {
+                       fileLoadComplete(event.target.info);
+        }
+        private function fileLoadComplete(info:Object):void {
+            var callbacks:Array = info.callbacks;
+            info.callbacks = null;
+            while (callbacks.length > 0) {
+                var callback:Function = callbacks.shift();
+                callback(this, info.filename);
+            }
+
+            fileReceived();
+               }
+               private function httpStatusHandler(event:HTTPStatusEvent):void { }
+               private function securityErrorHandler(event:SecurityErrorEvent):void { 
+                       trace("securityErrorEvent: "+event.target.url);
+                       fileReceived();
+               }
+               private function ioErrorHandler(event:IOErrorEvent):void { 
+                       trace("ioErrorEvent: "+event.target.url); 
+                       fileReceived();
+               }
+               private function fileReceived():void {
+                       filesReceived++;
+                       if (filesReceived==filesRequested) { dispatchEvent(new Event(FILES_LOADED)); }
+               }
+
+               /* ==========================================================================================
+                  Add files to bank from .zip file
+                  ========================================================================================== */
+               
+               public function addFromZip(filename:String, prefix:String=""):void {
+                       var loader:URLLoader = new URLLoader();
+                       loader.dataFormat="binary";
+                       loader.addEventListener(Event.COMPLETE, function(e:Event):void { zipReady(e,prefix); } );
+            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, zipSecurityErrorHandler);
+            loader.addEventListener(IOErrorEvent.IO_ERROR, zipIoErrorHandler);
+            zipsRequested++;
+            loader.load(new URLRequest(filename));
+               }
+               private function zipReady(event:Event, prefix:String):void {
+                       var zip:ZipFile = new ZipFile(event.target.data);
+                       for (var i:uint=0; i<zip.entries.length; i++) {
+                               var fileref:ZipEntry = zip.entries[i];
+                               var data:ByteArray = zip.getInput(fileref);
+                               if (isImageType(fileref.name)) {
+                                       // Store as an image
+                                       var loader:ExtendedLoader=new ExtendedLoader();
+                                       files[prefix+fileref.name]=loader;
+                    loader.info.filename = prefix+fileref.name;
+                                       loader.loadBytes(data);
+                               } else {
+                                       // Store as a document
+                                       var urlloader:ExtendedURLLoader=new ExtendedURLLoader();
+                                       files[prefix+fileref.name]=urlloader;
+                    urlloader.info.filename = prefix+fileref.name;
+                    urlloader.data = data.toString();
+                               }
+                       }
+            zipReceived();
+               }
+               private function zipSecurityErrorHandler(event:SecurityErrorEvent):void { 
+                       trace("securityErrorEvent: "+event.target.url);
+                       zipReceived();
+               }
+               private function zipIoErrorHandler(event:IOErrorEvent):void { 
+                       trace("ioErrorEvent: "+event.target.url); 
+                       zipReceived();
+               }
+               private function zipReceived():void {
+                       zipsReceived++;
+                       if (zipsReceived == zipsRequested) {
+                while (zipCallbacks.length > 0) {
+                    var callback:Function = zipCallbacks.shift();
+                    callback();
+                }
+            }
+               }
+               private function isImageType(filename:String):Boolean {
+                       if (filename.match(/\.jpe?g$/i) ||
+                               filename.match(/\.png$/i) ||
+                               filename.match(/\.gif$/i) ||
+                               filename.match(/\.swf$/i)) { return true; }
+                       return false;
+               }
+
+               /* ==========================================================================================
+                  Get files
+                  get(filename)
+                  getAsDisplayObject(filename)
+                  getAsBitmapData(filename)
+                  getAsByteArray(filename)
+                  ========================================================================================== */
+
+               public function get(name:String):String {
+                       return files[name];
+               }
+
+               public function getAsDisplayObject(name:String):DisplayObject {
+                       /* If the image hasn't loaded yet, then add an EventListener for when it does. */
+                       if (getWidth(name)==0) {
+                               var loader:Loader = new Loader();
+                               files[name].contentLoaderInfo.addEventListener(Event.COMPLETE,
+                                       function(e:Event):void { loaderReady(e, loader) });
+                               return loader;
+                       }
+                       /* Otherwise, create a new Bitmap, because just returning the raw Loader
+                          (i.e. files[name]) would only allow it to be added to one parent. (The other 
+                          way to do this would be by copying the bytes as loaderReady does.). */
+                       return new Bitmap(getAsBitmapData(name));
+               }
+               
+               public function getOriginalDisplayObject(name:String):DisplayObject {
+                       /* But if we're going to clone it later, this'll work fine. */
+                       return files[name];
+               }
+
+               private function loaderReady(event:Event, loader:Loader):void {
+                       /* The file has loaded, so we can copy the data from there into our new Loader */
+                       var info:LoaderInfo = event.target as LoaderInfo;
+                       loader.loadBytes(info.bytes);
+               }
+
+               public function getAsBitmapData(name:String):BitmapData {
+                       var bitmapData:BitmapData=new BitmapData(getWidth(name), getHeight(name), true, 0xFFFFFF);
+                       bitmapData.draw(files[name]);
+                       return bitmapData;
+               }
+               
+               public function getAsByteArray(name:String):ByteArray {
+                       return files[name].contentLoaderInfo.bytes;
+               }
+               
+               public function getAsString(name:String):String {
+                       return files[name].data;
+               }
+        
+               /* ==========================================================================================
+                  Get file information
+                  ========================================================================================== */
+
+               public function getWidth(name:String):int { 
+                       try { return files[name].contentLoaderInfo.width; }
+                       catch (error:Error) { } return 0;
+               }
+
+               public function getHeight(name:String):int { 
+                       try { return files[name].contentLoaderInfo.height; }
+                       catch (error:Error) { } return 0;
+               }
+
+       }
+}
diff --git a/net/systemeD/halcyon/ImageBank.as b/net/systemeD/halcyon/ImageBank.as
deleted file mode 100755 (executable)
index eca8547..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-package net.systemeD.halcyon {
-    import flash.events.*;
-       import flash.display.*;
-       import flash.net.*;
-       import flash.utils.ByteArray;
-       import nochump.util.zip.*;
-
-       /*
-               ImageBank stores and retrieves bitmap images.
-               All images are internally stored as Loader.
-
-               See blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/ for a really useful conversion guide!
-       */
-
-    public class ImageBank extends EventDispatcher{
-               private var images:Object={};
-               private var imagesRequested:uint=0;
-               private var imagesReceived:uint=0;
-               
-               public static const IMAGES_LOADED:String="imagesLoaded";
-               public static const ZIP_LOADED:String="zipLoaded";
-               
-               private static const GLOBAL_INSTANCE:ImageBank = new ImageBank();
-               public static function getInstance():ImageBank { return GLOBAL_INSTANCE; }
-
-               public function hasImage(name:String):Boolean {
-                       if (images[name]) return true;
-                       return false;
-               }
-
-               /* ==========================================================================================
-                  Populate with images 
-                  ========================================================================================== */
-
-               public function loadImage(filename:String):void {
-                       if (images[filename]) return;
-                       imagesRequested++;
-
-                       var loader:Loader=new Loader();
-                       images[filename]=loader;
-                       var request:URLRequest=new URLRequest(filename);
-                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE,                                               loadedImage);
-                       loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS,                  httpStatusHandler);
-                       loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,    securityErrorHandler);
-                       loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,                                ioErrorHandler);
-                       loader.load(request);
-               }
-
-               private function loadedImage(event:Event):void {
-                       imageReceived();
-               }
-               private function httpStatusHandler(event:HTTPStatusEvent):void { }
-               private function securityErrorHandler(event:SecurityErrorEvent):void { 
-                       trace("securityErrorEvent: "+event.target.url);
-                       imageReceived();
-               }
-               private function ioErrorHandler(event:IOErrorEvent):void { 
-                       trace("ioErrorEvent: "+event.target.url); 
-                       imageReceived();
-               }
-               private function imageReceived():void {
-                       imagesReceived++;
-                       if (imagesReceived==imagesRequested) { dispatchEvent(new Event(IMAGES_LOADED)); }
-               }
-
-               /* ==========================================================================================
-                  Load from .zip file
-                  ========================================================================================== */
-               
-               public function loadFromZip(filename:String, prefix:String=""):void {
-                       var loader:URLLoader = new URLLoader();
-                       loader.dataFormat="binary";
-                       loader.addEventListener(Event.COMPLETE, function(e:Event):void { zipReady(e,prefix); } );
-                       loader.load(new URLRequest(filename));
-               }
-               private function zipReady(event:Event, prefix:String):void {
-                       var zip:ZipFile = new ZipFile(event.target.data);
-                       for (var i:uint=0; i<zip.entries.length; i++) {
-                               var fileref:ZipEntry = zip.entries[i];
-                               var data:ByteArray = zip.getInput(fileref);
-                               var loader:Loader=new Loader();
-                               images[prefix+fileref.name]=loader;
-                               loader.loadBytes(data);
-                       }
-                       dispatchEvent(new Event(ZIP_LOADED));
-               }
-
-
-               /* ==========================================================================================
-                  Get images 
-                  getAsDisplayObject(filename)
-                  getAsBitmapData(filename)
-                  getAsByteArray(filename)
-                  ========================================================================================== */
-
-               public function getAsDisplayObject(name:String):DisplayObject {
-                       /* If the image hasn't loaded yet, then add an EventListener for when it does. */
-                       if (getWidth(name)==0) {
-                               var loader:Loader = new Loader();
-                               images[name].contentLoaderInfo.addEventListener(Event.COMPLETE,
-                                       function(e:Event):void { loaderReady(e, loader) });
-                               return loader;
-                       }
-                       /* Otherwise, create a new Bitmap, because just returning the raw Loader
-                          (i.e. images[name]) would only allow it to be added to one parent. (The other 
-                          way to do this would be by copying the bytes as loaderReady does.). */
-                       return new Bitmap(getAsBitmapData(name));
-               }
-               
-               public function getOriginalDisplayObject(name:String):DisplayObject {
-                       /* But if we're going to clone it later, this'll work fine. */
-                       return images[name];
-               }
-
-               private function loaderReady(event:Event, loader:Loader):void {
-                       /* The file has loaded, so we can copy the data from there into our new Loader */
-                       var info:LoaderInfo = event.target as LoaderInfo;
-                       loader.loadBytes(info.bytes);
-               }
-
-               public function getAsBitmapData(name:String):BitmapData {
-                       var bitmapData:BitmapData=new BitmapData(getWidth(name), getHeight(name), true, 0xFFFFFF);
-                       bitmapData.draw(images[name]);
-                       return bitmapData;
-               }
-               
-               public function getAsByteArray(name:String):ByteArray {
-                       return images[name].contentLoaderInfo.bytes;
-               }
-
-               /* ==========================================================================================
-                  Get file information
-                  ========================================================================================== */
-
-               public function getWidth(name:String):int { 
-                       try { return images[name].contentLoaderInfo.width; }
-                       catch (error:Error) { } return 0;
-               }
-
-               public function getHeight(name:String):int { 
-                       try { return images[name].contentLoaderInfo.height; }
-                       catch (error:Error) { } return 0;
-               }
-
-       }
-}
\ No newline at end of file
index 14801bc19265cb9ebe0be83a8ee1cf5fd7d34632..512d3398b36657e5aa4fdf06e31c64949cd467ac 100644 (file)
@@ -10,7 +10,7 @@ package net.systemeD.halcyon {
     import flash.geom.Point;
     import net.systemeD.halcyon.styleparser.*;
     import net.systemeD.halcyon.connection.*;
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
 
     public class MarkerUI extends EntityUI {
 
@@ -100,9 +100,9 @@ package net.systemeD.halcyon {
                             icon.graphics.drawCircle(w,w,w);
                             if (s.interactive) { maxwidth=Math.max(w,maxwidth); }
 
-                                               } else if (ImageBank.getInstance().hasImage(s.icon_image)) {
+                                               } else if (FileBank.getInstance().hasFile(s.icon_image)) {
                                                        // load icon from library
-                                                       icon.addChild(ImageBank.getInstance().getAsDisplayObject(s.icon_image));
+                                                       icon.addChild(FileBank.getInstance().getAsDisplayObject(s.icon_image));
 //                                                     addHitSprite(icon.width);                       // ** check this - we're doing it below too
 //                                                     loaded=true; updatePosition();          // ** check this
                                                        if (s.interactive) { maxwidth=Math.max(icon.width,maxwidth); }
index 51e9ec0f0e063df1763263803ca6ba4508c07ce5..94bc9f11d71285278c5ae057b208085ddae71741 100644 (file)
@@ -12,36 +12,29 @@ package net.systemeD.halcyon {
        *       onFeatureLoad can then access the XML via event.target.xml.
        */
 
+    import net.systemeD.halcyon.FileBank;
+
        import flash.events.*;
-    import flash.net.URLLoader;
-    import flash.net.URLRequest;
 
        public class NestedXMLLoader extends EventDispatcher {
                public var xml:XML = null;
-               private var url:String;
                private var count:int;
 
                public function NestedXMLLoader() {
                }
                
                public function load(url:String):void {
-                       this.url=url;
-                       var request:URLRequest=new URLRequest(url+"?d="+Math.random());
-                       var loader:URLLoader = new URLLoader();
-                       loader.addEventListener(Event.COMPLETE, fileLoaded);
-                       loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, fileError);
-                       loader.addEventListener(IOErrorEvent.IO_ERROR, fileError);
-                       loader.load(request);
+            FileBank.getInstance().addFromFile(url, fileLoaded);
                }
                
-               private function fileLoaded(event:Event):void {
-                       count=0;
-                       xml = new XML(URLLoader(event.target).data);
+               private function fileLoaded(fileBank:FileBank, filename:String):void {
+            count=1;
+                       xml = new XML(fileBank.getAsString(filename));
                        for each (var inc:XML in xml.descendants('include')) {
-                               replaceXML(inc);
                                count++;
+                               replaceXML(inc);
                        }
-                       if (count==0) { fireComplete(); }
+            decreaseCount();
                }
 
                private function replaceXML(inc:XML):void {
@@ -51,7 +44,7 @@ package net.systemeD.halcyon {
                                includeElement.parent().replace(findChildIndex(includeElement),event.target.xml);
                                decreaseCount();
                        });
-                       xmlLoader.load(inc.@file+"?d="+Math.random());
+                       xmlLoader.load(inc.@file);
                }
 
                private function findChildIndex(child:XML):int {
@@ -62,11 +55,6 @@ package net.systemeD.halcyon {
                        }
                        return -1;
                }
-
-               private function fileError(event:Event):void {
-                       // just fire a complete event so we don't get an error dialogue
-                       fireComplete();
-               }
                
                private function decreaseCount():void {
                        count--; if (count>0) return;
index 11bcc02fdd8a2daec449d3d49e43220927235333..9e26cc87571c1117f7355fb33a35addba7ed5077 100644 (file)
@@ -10,7 +10,7 @@ package net.systemeD.halcyon {
        import flash.geom.Point;
        import net.systemeD.halcyon.styleparser.*;
     import net.systemeD.halcyon.connection.*;
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
        
        /** The graphical representation of a Node (including POIs and nodes that are part of Ways). */
        public class NodeUI extends EntityUI {
@@ -122,9 +122,9 @@ package net.systemeD.halcyon {
                                                        icon.graphics.drawCircle(w,w,w);
                                                        if (s.interactive) { maxwidth=Math.max(w,maxwidth); }
 
-                                               } else if (ImageBank.getInstance().hasImage(s.icon_image)) {
+                                               } else if (FileBank.getInstance().hasFile(s.icon_image)) {
                                                        // load icon from library
-                                                       icon.addChild(ImageBank.getInstance().getAsDisplayObject(s.icon_image));
+                                                       icon.addChild(FileBank.getInstance().getAsDisplayObject(s.icon_image));
 //                                                     addHitSprite(icon.width);                       // ** check this - we're doing it below too
                                                        loaded=true; updatePosition();          // ** check this
                                                        if (s.interactive) { maxwidth=Math.max(icon.width,maxwidth); }
index f7a5945247f0f140752c152fb14c158798d02540..990f43bbe946681b92ee50e37e46bcd95101cd0a 100644 (file)
@@ -9,7 +9,7 @@ package net.systemeD.halcyon {
        
        import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.styleparser.*;
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
 
        /** The graphical representation of a Way. */ 
        public class WayUI extends EntityUI {
@@ -296,7 +296,7 @@ package net.systemeD.halcyon {
                                                fill=new Shape(); addToLayer(fill,FILLSPRITE,s.sublayer);
                                                fill.graphics.moveTo(x0,y0);
                                                if (s.fill_image) {
-                                                       fill.graphics.beginBitmapFill(ImageBank.getInstance().getAsBitmapData(s.fill_image));
+                                                       fill.graphics.beginBitmapFill(FileBank.getInstance().getAsBitmapData(s.fill_image));
                                                } else {
                                                        s.applyFill(fill.graphics);
                                                }
index fc046c251964e5f29d618aac1b056a6e838d21d6..2cd5f0958c2b210f8dc1778fa9d4fd53235307d6 100644 (file)
@@ -162,11 +162,19 @@ package net.systemeD.halcyon.connection {
            }
 
         private function changesetCreateComplete(event:Event):void {
-            // response should be a Number changeset id
-            var id:Number = Number(URLLoader(event.target).data);
+            var result:String = URLLoader(event.target).data;
+
+            if (result.match(/^^\d+$/)) {
+                // response should be a Number changeset id
+                var id:Number = Number(URLLoader(event.target).data);
             
-            // which means we now have a new changeset!
-            setActiveChangeset(new Changeset(this, id, lastUploadedChangesetTags));
+                // which means we now have a new changeset!
+                setActiveChangeset(new Changeset(this, id, lastUploadedChangesetTags));
+            } else {
+                var results:XML = XML(result);
+
+                throwServerError(results.message);
+            }
         }
 
         private function changesetCreateError(event:IOErrorEvent):void {
index b03f1b381de5fe3f29082a8e975cc397020986d8..1873d57655b1ebe8327c9c8f377b3e3e0359d781 100644 (file)
@@ -1,9 +1,8 @@
 package net.systemeD.halcyon.styleparser {
 
-       import flash.events.*;
-       import flash.net.URLLoader;
-       import flash.net.URLLoaderDataFormat;
-       import flash.net.URLRequest;
+    import net.systemeD.halcyon.FileBank;
+
+    import flash.events.*;
 
        /** A class permitting you to load CSS files containing 'import' rules, which will be 
                automatically replaced with the contents of the file.                                                                   <p>
@@ -18,9 +17,7 @@ package net.systemeD.halcyon.styleparser {
        */
 
        public class NestedCSSLoader extends EventDispatcher {
-               private var sourceCSS:String;
                public var css:String;
-               private var url:String;
                private var count:int;
 
                private static const IMPORT:RegExp=/@import\s*[^'"]*['"]([^'"]+)['"][^;]*;/g;           // '
@@ -29,28 +26,21 @@ package net.systemeD.halcyon.styleparser {
                }
                
                public function load(url:String):void {
-                       this.url=url;
-                       var request:URLRequest=new URLRequest(url+"?d="+Math.random());
-                       var loader:URLLoader = new URLLoader();
-                       loader.dataFormat = URLLoaderDataFormat.TEXT;
-                       loader.addEventListener(Event.COMPLETE, fileLoaded);
-                       loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, fileError);
-                       loader.addEventListener(IOErrorEvent.IO_ERROR, fileError);
-                       loader.load(request);
+            FileBank.getInstance().addFromFile(url, fileLoaded);
                }
                
-               private function fileLoaded(event:Event):void {
-                       sourceCSS=URLLoader(event.target).data;
-                       css=sourceCSS;
-                       count=0;
+               private function fileLoaded(fileBank:FileBank, filename:String):void {
+                       css = fileBank.getAsString(filename);
+                       count = 1;
 
-                       var result:Object=IMPORT.exec(sourceCSS);
-                       while (result!=null) {
+                       var results:Array = css.match(IMPORT);
+            while (results.length > 0) {
+                IMPORT.lastIndex = 0;
+                var result:Object = IMPORT.exec(results.shift());
                                count++;
                                replaceCSS(result[1],result[0]);
-                               result=IMPORT.exec(sourceCSS);
                        }
-                       if (count==0) { fireComplete(); }
+            decreaseCount();
                }
 
                private function replaceCSS(filename:String, toReplace:String):void {
@@ -60,13 +50,7 @@ package net.systemeD.halcyon.styleparser {
                                css=css.replace(replaceText,event.target.css);
                                decreaseCount();
                        });
-                       cssLoader.load(filename+"?d="+Math.random());
-               }
-
-               private function fileError(event:Event):void {
-                       // just fire a complete event so we don't get an error dialogue
-                       trace("Error while trying to load "+url);
-                       fireComplete();
+                       cssLoader.load(filename);
                }
                
                private function decreaseCount():void {
index 6a8d6a015fef1dda52b38a08015078c7a0bf23f5..cbe58be776c105f32fe6bfb4534f1631a65970d6 100644 (file)
@@ -2,11 +2,8 @@ package net.systemeD.halcyon.styleparser {
 
        import flash.events.*;
        import flash.net.*;
-       import net.systemeD.halcyon.ExtendedLoader;
-       import net.systemeD.halcyon.ExtendedURLLoader;
-       import net.systemeD.halcyon.DebugURLRequest;
     import net.systemeD.halcyon.connection.Entity;
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
 
     import net.systemeD.halcyon.connection.*;
 
@@ -294,7 +291,6 @@ package net.systemeD.halcyon.styleparser {
                /** Load all images referenced in the RuleSet (for example, icons or bitmap fills). */
                
                private function loadImages():void {
-                       ImageBank.getInstance().addEventListener(ImageBank.IMAGES_LOADED,doIconCallback);
                        var filename:String;
                        for each (var chooser:StyleChooser in choosers) {
                                for each (var style:Style in chooser.styles) {
@@ -304,13 +300,10 @@ package net.systemeD.halcyon.styleparser {
                                        else { continue; }
 
                                        if (filename!='square' && filename!='circle')
-                                               ImageBank.getInstance().loadImage(filename);
+                                               FileBank.getInstance().addFromFile(filename);
                                }
                        }
-               }
-               
-               private function doIconCallback(e:Event):void {
-                       iconCallback();
+            FileBank.getInstance().onFilesLoaded(iconCallback);
                }
                
                // ------------------------------------------------------------------------------------------------
index 9d9d2f93fc4648a94287b5f8d3582eafedb6ff83..f0e95bc50745152858eabec3721315a1b5927622 100644 (file)
@@ -1,7 +1,7 @@
 package net.systemeD.halcyon.styleparser {
 
        import net.systemeD.halcyon.connection.Entity;
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
 
        public class StyleChooser {
 
@@ -68,8 +68,8 @@ package net.systemeD.halcyon.styleparser {
                                                        if (PointStyle(r).icon_width && !PointStyle(r).evals['icon_width']) {
                                                                // ** FIXME: we should check this is the bit being used for 'square', 'circle' etc.
                                                                w=PointStyle(r).icon_width;
-                                                       } else if (PointStyle(r).icon_image && ImageBank.getInstance().hasImage(PointStyle(r).icon_image)) {
-                                                               w=ImageBank.getInstance().getWidth(PointStyle(r).icon_image);
+                                                       } else if (PointStyle(r).icon_image && FileBank.getInstance().hasFile(PointStyle(r).icon_image)) {
+                                                               w=FileBank.getInstance().getWidth(PointStyle(r).icon_image);
                                                        }
                                                        if (w>sl.maxwidth) { sl.maxwidth=w; }
                                                } else if (r is InstructionStyle) {
diff --git a/net/systemeD/potlatch2/CustomLocaleCommand.as b/net/systemeD/potlatch2/CustomLocaleCommand.as
new file mode 100644 (file)
index 0000000..b4b8160
--- /dev/null
@@ -0,0 +1,24 @@
+package net.systemeD.potlatch2 {
+    import org.babelfx.commands.ExternalLocaleCommand;
+    import net.systemeD.halcyon.Globals;
+
+    public class CustomLocaleCommand extends ExternalLocaleCommand {
+        public var defaultExternalPath:String;
+
+        override protected function loadLocale(locale:String):void {
+            externalPath = defaultExternalPath;
+
+            if (Globals.vars.locale_paths) {
+                for each (var path:String in Globals.vars.locale_paths.split(";")) {
+                    var args:Array = path.split("=");
+
+                    if (args[0] == locale) {
+                        externalPath = args[1];
+                    }
+                }
+            }
+
+            super.loadLocale(locale);
+        }
+    }
+}
index 583e610339e1e70a58657efe38c55654738efa2f..ebef62df03e06c52b442ffcc00ce53e7ed923bad 100644 (file)
@@ -6,7 +6,7 @@ package net.systemeD.potlatch2 {
     import flash.geom.Matrix;
     import flash.text.TextField;
     import flash.text.TextFormat;
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
 
 
     public class Preloader extends net.systemeD.potlatch2.PreloaderDisplayBase {
@@ -21,9 +21,6 @@ package net.systemeD.potlatch2 {
         private var barFrame:Sprite;
         private var mainColor:uint=0x045966;
 
-               private var assetscount:uint=0;
-               private var queuedEvents:Array=[];
-
         public function Preloader()
         {
             super();
@@ -45,31 +42,16 @@ package net.systemeD.potlatch2 {
 
                        // request .zip files
                        if (loaderInfo.parameters['assets']) {
-                               ImageBank.getInstance().addEventListener(ImageBank.ZIP_LOADED, zipLoaded);
                                for each (var file:String in loaderInfo.parameters['assets'].split(';')) {
                                        var asset:Array=file.split('=');
-                                       assetscount++;
-                                       ImageBank.getInstance().loadFromZip(asset[0],asset[1]);
+                    if (asset.length == 1) {
+                        FileBank.getInstance().addFromZip(asset[0]);
+                    } else {
+                        FileBank.getInstance().addFromZip(asset[0], asset[1]);
+                    }
                                }
                        }
         }
-
-               override protected function initProgressHandler(e:Event):void {
-                       // We don't let anything happen until the .zips are loaded
-                       // see http://stackoverflow.com/questions/2773617/how-to-preload-a-file-in-flex-before-the-application-initializes
-                       if (assetscount>0) {
-                               queuedEvents.push(e);
-                               e.stopImmediatePropagation();
-                       }
-                       draw();
-               }
-               
-               private function zipLoaded(e:Event):void {
-                       assetscount--; if (assetscount>0) return;
-                       for each (var q:Event in queuedEvents) {
-                               dispatchEvent(q);
-                       }
-               }
                
         //this is our "animation" bit
         override protected function draw():void
index f8abb7cff5f8868b57c8ab0db73f3a27885e7f33..069ae6724e6717ba12af883572a32dd44b1f26a6 100644 (file)
@@ -4,7 +4,7 @@ package net.systemeD.potlatch2.collections {
        import flash.display.*;
        import flash.net.*;
        import flash.text.TextField;
-       import net.systemeD.halcyon.DebugURLRequest;
+       import net.systemeD.halcyon.FileBank;
        import net.systemeD.halcyon.Map;
        import net.systemeD.halcyon.MapEvent;
        import net.systemeD.potlatch2.FunctionKeyManager;
@@ -38,18 +38,15 @@ package net.systemeD.potlatch2.collections {
                        _yahoo = yahoo;
 
                        // load imagery file
-               var request:DebugURLRequest = new DebugURLRequest("imagery.xml");
-               var loader:URLLoader = new URLLoader();
-               loader.addEventListener(Event.COMPLETE, onImageryLoad);
-               loader.load(request.request);
+            FileBank.getInstance().addFromFile("imagery.xml", onImageryLoad);
 
                        // create map listeners
                        map.addEventListener(MapEvent.MOVE, moveHandler);
                        map.addEventListener(MapEvent.RESIZE, resizeHandler);
                }
 
-        private function onImageryLoad(event:Event):void {
-                       var xml:XML = new XML(URLLoader(event.target).data);
+               private function onImageryLoad(fileBank:FileBank, filename:String):void {
+                       var xml:XML = new XML(fileBank.getAsString(filename));
                        var saved:Object = {};
                        var bg:Object;
                        if (SharedObject.getLocal("user_state").data['background_url']!=undefined) {
@@ -98,11 +95,12 @@ package net.systemeD.potlatch2.collections {
                        collection.forEach(function(bg:Object, index:int, array:Array):void {
                                if (bg.logo) {
                                        // load the logo
-                                       var loader:Loader = new Loader();
-                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void { onLogoLoad(e,bg); });
-                                       loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
-                                       loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
-                                       loader.load(new URLRequest(bg.logo));
+                    FileBank.getInstance().addFromFile(bg.logo, function (fb:FileBank, name:String):void {
+                        bg.logoData = fb.getAsBitmapData(name);
+                        bg.logoWidth = fb.getWidth(name);
+                        bg.logoHeight = fb.getHeight(name);
+                        setLogo();
+                    });
                                }
                                if (bg.attribution_url) {
                                        // load the attribution
@@ -124,13 +122,6 @@ package net.systemeD.potlatch2.collections {
                        // placeholder error routine so exception isn't thrown
                }
                
-               public function onLogoLoad(e:Event, bg:Object):void {
-                       bg.logoData  = Bitmap(LoaderInfo(e.target).content).bitmapData;
-                       bg.logoWidth = e.target.loader.width;
-                       bg.logoHeight= e.target.loader.height;
-                       setLogo();
-               }
-               
                public function onAttributionLoad(e:Event,bg: Object):void {
                        // if we ever need to cope with non-Microsoft attribution, then this should look at bg.scheme
             default xml namespace = Namespace("http://schemas.microsoft.com/search/local/ws/rest/v1");
index 1ac3f63dd2c799ac284460df2881240f1a4485b0..3ffc6693a42e5a97b3d2c7390bfa7303710ac541 100644 (file)
@@ -3,7 +3,7 @@ package net.systemeD.potlatch2.collections {
        import flash.events.EventDispatcher;
        import flash.events.Event;
        import flash.net.*;
-       import net.systemeD.halcyon.DebugURLRequest;
+       import net.systemeD.halcyon.FileBank;
        import net.systemeD.halcyon.Map;
        import net.systemeD.potlatch2.FunctionKeyManager;
        import net.systemeD.potlatch2.Yahoo;
@@ -28,14 +28,13 @@ package net.systemeD.potlatch2.collections {
                        _selected=_selected ? _selected : DEFAULT;
                        
                        // Load the stylesheet catalogue
-                       var request:DebugURLRequest = new DebugURLRequest("stylesheets.xml");
-                       var loader:URLLoader = new URLLoader();
-               loader.addEventListener(Event.COMPLETE, function(e:Event):void { onStylesheetsLoad(e,request_url); });
-               loader.load(request.request);
+            FileBank.getInstance().addFromFile("stylesheets.xml", function (fb:FileBank, name:String):void {
+                onStylesheetsLoad(fb, name, request_url);
+            });
                }
 
-               private function onStylesheetsLoad(event:Event, request_url:String=null):void {
-                       var xml:XML = new XML(URLLoader(event.target).data);
+               private function onStylesheetsLoad(fileBank:FileBank, filename:String, request_url:String=null):void {
+                       var xml:XML = new XML(fileBank.getAsString(filename));
                        var saved_url:String = SharedObject.getLocal("user_state").data['stylesheet_url'];
                        var saved_name:String= SharedObject.getLocal("user_state").data['stylesheet_name'];
                        if (request_url && request_url!=saved_url) { saved_url=request_url; saved_name='Custom'; }
index 9b64e3a0a7ac6b3324124c01bc7d6357239ac02e..0a8d61086548fd4d982f9a6800b0942e89a2952d 100644 (file)
@@ -6,7 +6,7 @@ package net.systemeD.potlatch2.collections {
        import net.systemeD.halcyon.Map;
        import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.connection.Connection;
-       import net.systemeD.halcyon.DebugURLRequest;
+       import net.systemeD.halcyon.FileBank;
        import net.systemeD.potlatch2.utils.*;
                
        public class VectorBackgrounds extends EventDispatcher {
@@ -19,14 +19,11 @@ package net.systemeD.potlatch2.collections {
 
                public function init(map:Map):void {
                        _map = map;
-                       var request:DebugURLRequest = new DebugURLRequest("vectors.xml");
-                       var loader:URLLoader = new URLLoader();
-                       loader.addEventListener(Event.COMPLETE, onConfigLoad);
-                       loader.load(request.request);
+            FileBank.getInstance().addFromFile("vectors.xml", onConfigLoad);
                }
 
-               public function onConfigLoad(e:Event):void {
-                       var xml:XML = XML(e.target.data);
+               private function onConfigLoad(fileBank:FileBank, filename:String):void {
+                       var xml:XML = new XML(fileBank.getAsString(filename));
 
                        // reconstitute results as Array, as we can't run .forEach over an XMLList
                        var sets:Array = [];
index 0c246d2fb4b25c01a9e385b35f3823a1e9a4623b..8ae89c8ed5c33fa7bad87a6034ca2fcc14691426 100644 (file)
@@ -8,9 +8,8 @@ package net.systemeD.potlatch2.mapfeatures {
     import mx.core.BitmapAsset;
     import mx.graphics.codec.PNGEncoder;
     
-    import net.systemeD.halcyon.ImageBank;
+    import net.systemeD.halcyon.FileBank;
     import net.systemeD.halcyon.connection.Entity;
-    import net.systemeD.potlatch2.utils.CachedDataLoader;
 
         /** A "map feature" is sort of a template for a map entity. It consists of a few crucial key/value pairs that define the feature, so that
          * entities can be recognised. It also contains optional keys, with associated editing controls, that are defined as being appropriate
@@ -32,10 +31,23 @@ package net.systemeD.potlatch2.mapfeatures {
         public function Feature(mapFeatures:MapFeatures, _xml:XML) {
             this.mapFeatures = mapFeatures;
             this._xml = _xml;
+            loadImages();
             parseConditions();
             parseEditors();
         }
 
+        private function loadImages():void {
+            var icon:XMLList = _xml.icon;
+            if ( icon.length() > 0 ) {
+                if ( icon[0].hasOwnProperty("@dnd") ) {
+                    FileBank.getInstance().addFromFile(icon[0].@dnd);
+                }
+                if ( icon[0].hasOwnProperty("@image") ) {
+                    FileBank.getInstance().addFromFile(icon[0].@image);
+                }
+            }
+        }
+
         private function parseConditions():void {
             _tags = [];
            _withins = [];
@@ -138,6 +150,7 @@ package net.systemeD.potlatch2.mapfeatures {
         /** Fetches the feature's image, as defined by the icon element in the feature definition.
         * @param dnd if true, overrides the normal image and returns the one defined by the dnd property instead. */
         private function getImage(dnd:Boolean = false):ByteArray {
+            var fileBank:FileBank = FileBank.getInstance();
             var icon:XMLList = _xml.icon;
             var imageURL:String;
 
@@ -147,12 +160,12 @@ package net.systemeD.potlatch2.mapfeatures {
                 imageURL = icon[0].@image;
             }
 
-            if ( imageURL ) {
-                               if (ImageBank.getInstance().hasImage(imageURL)) {
-                                       return ImageBank.getInstance().getAsByteArray(imageURL)
-                               } else {
-                       return CachedDataLoader.loadData(imageURL, imageLoaded);
-                               }
+            if ( imageURL && fileBank.hasFile(imageURL) ) {
+                if (fileBank.fileLoaded(imageURL, imageLoaded)) {
+                    return fileBank.getAsByteArray(imageURL);
+                } else {
+                    return null;
+                }
             }
             var bitmap:BitmapAsset = new missingIconCls() as BitmapAsset;
             return new PNGEncoder().encode(bitmap.bitmapData);
@@ -166,7 +179,7 @@ package net.systemeD.potlatch2.mapfeatures {
                return point.length() > 0 && !(XML(point[0]).attribute("draganddrop")[0] == "no");
         }
 
-        private function imageLoaded(url:String, data:ByteArray):void {
+        private function imageLoaded(fileBank:FileBank, url:String):void {
             dispatchEvent(new Event("imageChanged"));
         }
 
index 5dc5b02d518cd1fb3f7f419645543875432e0143..98cd47c39fc422ddd82cbc98a14e4f7ae8ff9bc5 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2.mapfeatures {
     import flash.events.EventDispatcher;
     import flash.net.*;
     
+    import net.systemeD.halcyon.FileBank;
     import net.systemeD.halcyon.NestedXMLLoader;
     import net.systemeD.halcyon.connection.*;
 
index 2b390c1bbc6c900110b5e3ba91a4c5f4aa1d5ea4..891da56499d8df9ac70fe544218160f72e021add 100644 (file)
@@ -27,11 +27,6 @@ package net.systemeD.potlatch2.mapfeatures.editors {
                 _match = new RegExp("^("+matchStr+")$");
             }
         }
-        
-        public function imageLoaded(url:String, data:ByteArray):void {
-            icon = data;
-            dispatchEvent(new Event("iconLoaded"));
-        }
     }
 
 }
index 6beaa3d478e4f8296b8d7e0bd38ecc6ea11984f9..4cc1e0f2ca1ddb617b4d22550d9048da8027c360 100644 (file)
@@ -2,8 +2,9 @@ package net.systemeD.potlatch2.mapfeatures.editors {
 
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.mapfeatures.*;
-    import net.systemeD.potlatch2.utils.CachedDataLoader;
+    import net.systemeD.halcyon.FileBank;
     import flash.display.*;
+    import flash.events.*;
 
        public class ChoiceEditorFactory extends SingleTagEditorFactory {
            public var choices:Array;
@@ -12,14 +13,22 @@ package net.systemeD.potlatch2.mapfeatures.editors {
             super(inputXML,"horizontal");
             
             choices = [];
+
+            var fileBank:FileBank = FileBank.getInstance();
+            
             for each( var choiceXML:XML in inputXML.choice ) {
                 var choice:Choice = new Choice();
                 choice.value = String(choiceXML.@value);
                 choice.description = String(choiceXML.@description);
                 choice.label = String(choiceXML.@text);
-                choice.icon = choiceXML.hasOwnProperty("@icon") ? 
-                    CachedDataLoader.loadData(String(choiceXML.@icon), choice.imageLoaded) : null;
                 choice.match = String(choiceXML.@match);
+                if (choiceXML.hasOwnProperty("@icon")) {
+                    var icon:String = String(choiceXML.@icon);
+                    fileBank.addFromFile(icon, function (fb:FileBank, name:String):void {
+                        choice.icon = fb.getAsByteArray(name);
+                        choice.dispatchEvent(new Event("iconLoaded"));
+                    });
+                }
                 choices.push(choice);
             }
         }
diff --git a/net/systemeD/potlatch2/utils/CachedDataLoader.as b/net/systemeD/potlatch2/utils/CachedDataLoader.as
deleted file mode 100644 (file)
index 0947c4b..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-package net.systemeD.potlatch2.utils {
-
-       import flash.events.*;
-       import flash.net.*;
-       import flash.utils.ByteArray;
-       import flash.display.BitmapData;
-       import mx.graphics.codec.PNGEncoder;
-
-    import net.systemeD.halcyon.ExtendedURLLoader;
-       import net.systemeD.halcyon.DebugURLRequest;
-
-       public class CachedDataLoader {
-
-        private static var allData:Object = {};
-        private static var requestsMade:Object = {};
-        private static var missingImage:ByteArray = null;
-        
-               public static function loadData(url:String, onLoadHandler:Function = null):ByteArray {
-                   var data:ByteArray = allData[url];
-                   if ( data != null )
-                       return data;
-                   
-                   var requests:Array = requestsMade[url];
-                   if ( requests == null ) {
-                       requests = [];
-                       requestsMade[url] = requests;
-
-                               var request:DebugURLRequest = new DebugURLRequest(url);
-                           var loader:ExtendedURLLoader = new ExtendedURLLoader();
-                   loader.info = url;
-                loader.addEventListener(Event.COMPLETE, imageLoaded);
-                loader.addEventListener(IOErrorEvent.IO_ERROR, imageLoadFailed);
-                loader.dataFormat = URLLoaderDataFormat.BINARY;
-                loader.load(request.request);
-                   }
-                   requests.push(onLoadHandler);
-                   
-                   return allData[url];
-               }
-
-        private static function imageLoaded(event:Event):void {
-            var loader:ExtendedURLLoader = ExtendedURLLoader(event.target);
-            var url:String = loader.info as String;
-            allData[url] = loader.data;
-            dispatchEvents(url);
-        }
-        
-        private static function imageLoadFailed(event:Event):void {
-            var loader:ExtendedURLLoader = ExtendedURLLoader(event.target);
-            var url:String = loader.info as String;
-            
-            allData[url] = getMissingImage();
-            dispatchEvents(url);
-        }
-        
-        private static function dispatchEvents(url:String):void {
-            var requests:Array = requestsMade[url];
-            for each ( var handler:Function in requests ) {
-                handler(url, allData[url]);
-            }
-            
-            delete requestsMade[url];
-        }
-        
-        private static function getMissingImage():ByteArray {
-            if ( missingImage == null ) {
-                var bitmap:BitmapData = new BitmapData(24, 24, false);
-                for ( var i:uint = 0; i < 24; i++ ) {
-                    bitmap.setPixel(i, i, 0xff0000);
-                    bitmap.setPixel(23-i, i, 0xff0000);
-                }
-                missingImage = new PNGEncoder().encode(bitmap);
-            }
-            return missingImage;
-        }
-       }
-}
index c6e29f8cd35eedc5d767536848fb4480c21960a2..af5e5c4891e76f4c0ee4e53f8ec439e54822f128 100644 (file)
                private function startInit():void {
                        var loader:Loader = new Loader();
                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startApp);
-                       loader.load(new URLRequest("FontLibrary.swf"));
+            if (loaderInfo.parameters['font_library']) {
+                           loader.load(new URLRequest(loaderInfo.parameters['font_library']));
+            } else {
+                           loader.load(new URLRequest("FontLibrary.swf"));
+            }
 
             if (loaderInfo.parameters['locale'] && loaderInfo.parameters['locale']!='en_US') {
                 // we don't bother with localisation if the user is en_US, as P2 is in English by default
                 Globals.vars.locale = loaderInfo.parameters['locale'];
+                Globals.vars.locale_paths = loaderInfo.parameters['locale_paths'];
                 dispatchEvent(new LocaleEvent(LocaleEvent.LOAD_LOCALE, loaderInfo.parameters['locale']));
                 dispatchEvent(new LocaleEvent(LocaleEvent.LOAD_LOCALE, 'en_US')); // think en_US is default
                 resourceManager.localeChain = [loaderInfo.parameters['locale'], 'en_US'];