Add onFilesLoaded to FileBank to handle callbacks
authorTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 12:18:53 +0000 (12:18 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 12:18:53 +0000 (12:18 +0000)
We can't use rely on the FILES_LOADED event because if there are no
files to load it will never fire, so introduce a new routine that will
do an immediate callback in that case, and a deferred one otherwise.

net/systemeD/halcyon/FileBank.as
net/systemeD/halcyon/styleparser/RuleSet.as

index d82a2d7..2f277de 100755 (executable)
@@ -56,7 +56,17 @@ package net.systemeD.halcyon {
                        }
                }
 
-               private function loadedImage(event:Event):void {
+        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 {
                        fileReceived();
                }
                private function httpStatusHandler(event:HTTPStatusEvent):void { }
@@ -170,4 +180,4 @@ package net.systemeD.halcyon {
                }
 
        }
-}
\ No newline at end of file
+}
index d084214..83f197b 100644 (file)
@@ -294,7 +294,6 @@ package net.systemeD.halcyon.styleparser {
                /** Load all images referenced in the RuleSet (for example, icons or bitmap fills). */
                
                private function loadImages():void {
-                       FileBank.getInstance().addEventListener(FileBank.FILES_LOADED,doIconCallback);
                        var filename:String;
                        for each (var chooser:StyleChooser in choosers) {
                                for each (var style:Style in chooser.styles) {
@@ -307,10 +306,7 @@ package net.systemeD.halcyon.styleparser {
                                                FileBank.getInstance().addFromFile(filename);
                                }
                        }
-               }
-               
-               private function doIconCallback(e:Event):void {
-                       iconCallback();
+            FileBank.getInstance().onFilesLoaded(iconCallback);
                }
                
                // ------------------------------------------------------------------------------------------------