Load XML files through the FileBank
authorTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 16:03:08 +0000 (16:03 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 19:07:32 +0000 (19:07 +0000)
net/systemeD/halcyon/NestedXMLLoader.as

index 51e9ec0..94bc9f1 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;