disable caching when using Flash Debug Player
authorRichard Fairhurst <richard@systemed.net>
Tue, 31 Aug 2010 14:32:32 +0000 (14:32 +0000)
committerRichard Fairhurst <richard@systemed.net>
Tue, 31 Aug 2010 14:32:32 +0000 (14:32 +0000)
TODO.txt
net/systemeD/halcyon/DebugURLRequest.as [new file with mode: 0644]
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/potlatch2/mapfeatures/MapFeatures.as
net/systemeD/potlatch2/utils/CachedDataLoader.as
net/systemeD/potlatch2/utils/Importer.as
potlatch2.mxml

index 2f0f1d6..b57e7b9 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -60,7 +60,6 @@ Requested enhancements
 
 == Other core ==
 
-* Disable caching (i.e. set all URLRequests to POST) if URL parameter passed
 * Non-900913 projections
 * Plugin support
 * Support undo / redo across saving events
diff --git a/net/systemeD/halcyon/DebugURLRequest.as b/net/systemeD/halcyon/DebugURLRequest.as
new file mode 100644 (file)
index 0000000..3eabbc3
--- /dev/null
@@ -0,0 +1,33 @@
+package net.systemeD.halcyon {
+
+       /*
+               === DebugURLRequest ===
+
+               If this is running under a Flash debug player, this will make the URLRequest using POST 
+               rather than GET - thereby preventing FP from caching it
+               (see http://www.ultrashock.com/forums/actionscript/force-reload-files-only-using-as3-123408.html).
+               
+               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.
+
+       */
+
+       import flash.net.URLRequest;
+       import flash.net.URLRequestMethod;
+       import flash.system.Capabilities;
+
+       public class DebugURLRequest {
+
+               public var request:URLRequest;
+
+               public function DebugURLRequest(url:String=null) {
+                       request=new URLRequest(url);
+                       if (Capabilities.isDebugger) {
+                               request.method=URLRequestMethod.POST;
+                               request.data=true;
+                       }
+               }
+
+       }
+
+}
index a617a50..d066487 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.halcyon.styleparser {
        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.connection.*;
@@ -241,16 +242,16 @@ package net.systemeD.halcyon.styleparser {
                public function loadFromCSS(str:String):void {
                        if (str.match(/[\s\n\r\t]/)!=null) { parseCSS(str); loaded=true; redrawCallback(); return; }
 
-                       var request:URLRequest=new URLRequest(str+"?"+Math.random());
+                       var request:DebugURLRequest=new DebugURLRequest(str);
                        var loader:URLLoader=new URLLoader();
 
-                       request.method=URLRequestMethod.GET;
+//                     request.method=URLRequestMethod.GET;
                        loader.dataFormat = URLLoaderDataFormat.TEXT;
                        loader.addEventListener(Event.COMPLETE,                                         doParseCSS);
                        loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler);
                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
                        loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
-                       loader.load(request);
+                       loader.load(request.request);
                }
 
                private function doParseCSS(e:Event):void {
@@ -280,7 +281,7 @@ package net.systemeD.halcyon.styleparser {
                                        if (filename=='square' || filename=='circle') { continue; }
                                
                                        iconsToLoad++;
-                                       var request:URLRequest=new URLRequest(filename);
+                                       var request:DebugURLRequest=new DebugURLRequest(filename);
                                        var loader:ExtendedURLLoader=new ExtendedURLLoader();
                                        loader.dataFormat=URLLoaderDataFormat.BINARY;
                                        loader.info['filename']=filename;
@@ -288,7 +289,7 @@ package net.systemeD.halcyon.styleparser {
                                        loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler,              false, 0, true);
                                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler,   false, 0, true);
                                        loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler,                 false, 0, true);
-                                       loader.load(request);
+                                       loader.load(request.request);
                                }
                        }
                }
index 13428df..d9f64e5 100644 (file)
@@ -3,13 +3,12 @@ package net.systemeD.potlatch2.mapfeatures {
     import flash.events.EventDispatcher;
     import flash.events.Event;
     import flash.net.URLLoader;
-    import flash.net.URLRequest;
 
        import flash.system.Security;
        import flash.net.*;
 
     import net.systemeD.halcyon.connection.*;
-
+       import net.systemeD.halcyon.DebugURLRequest;
 
        public class MapFeatures extends EventDispatcher {
         private static var instance:MapFeatures;
@@ -29,10 +28,10 @@ package net.systemeD.potlatch2.mapfeatures {
         private var _categories:Array = null;
 
         protected function loadFeatures():void {
-            var request:URLRequest = new URLRequest("map_features.xml?"+Math.random());
+            var request:DebugURLRequest = new DebugURLRequest("map_features.xml");
             var loader:URLLoader = new URLLoader();
             loader.addEventListener(Event.COMPLETE, onFeatureLoad);
-            loader.load(request);
+            loader.load(request.request);
         }
 
         internal function get definition():XML {
index c790cc6..17b6c18 100644 (file)
@@ -7,6 +7,7 @@ package net.systemeD.potlatch2.utils {
        import mx.graphics.codec.PNGEncoder;
 
     import net.systemeD.halcyon.ExtendedURLLoader;
+       import net.systemeD.halcyon.DebugURLRequest;
 
        public class CachedDataLoader {
 
@@ -24,12 +25,13 @@ package net.systemeD.potlatch2.utils {
                        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(new URLRequest(url));
+                loader.load(request.request);
                    }
                    requests.push(onLoadHandler);
                    
index 6f4f474..8c5d858 100644 (file)
@@ -2,6 +2,7 @@ package net.systemeD.potlatch2.utils {
 
        import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.ExtendedURLLoader;
+       import net.systemeD.halcyon.DebugURLRequest;
        import flash.net.URLLoader;
        import flash.display.LoaderInfo;
        import flash.events.*;
@@ -34,6 +35,7 @@ package net.systemeD.potlatch2.utils {
                        for each (var fn:String in filenames) {
                                Globals.vars.root.addDebug("requesting file "+fn); 
 
+                               var request:DebugURLRequest = new DebugURLRequest(fn);
                                var loader:ExtendedURLLoader = new ExtendedURLLoader();
                                loader.info['file']=sp;
                                loader.dataFormat=URLLoaderDataFormat.BINARY;
@@ -42,7 +44,7 @@ package net.systemeD.potlatch2.utils {
                                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
                                        loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
                                }
-                               loader.load(new URLRequest(fn));
+                               loader.load(request.request);
                                sp++;
                        }
                }
index 5866bb0..cdfcdb9 100755 (executable)
                        if (objChanged) { obj.flush(); }
 
                        // load imagery and style XML
-               var request:URLRequest = new URLRequest("imagery.xml?"+Math.random());
+               var request:DebugURLRequest = new DebugURLRequest("imagery.xml");
                var loader:URLLoader = new URLLoader();
                loader.addEventListener(Event.COMPLETE, onImageryLoad);
-               loader.load(request);
+               loader.load(request.request);
 
-                       var request2:URLRequest = new URLRequest("stylesheets.xml?"+Math.random());
+                       var request2:DebugURLRequest = new DebugURLRequest("stylesheets.xml");
                        var loader2:URLLoader = new URLLoader();
                loader2.addEventListener(Event.COMPLETE, onStylesheetsLoad);
-               loader2.load(request2);
+               loader2.load(request2.request);
 
                        // map backdrop object
             var w:uint = map_area.width;