Rework handling of choice editor images
authorTom Hughes <tom@compton.nu>
Sun, 25 Mar 2012 20:19:23 +0000 (21:19 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 25 Mar 2012 20:19:23 +0000 (21:19 +0100)
I have no idea why this aproach works better, but it seems to lead
to more reliable loading of the images and is closer to the way the
original pre-FileBank code worked.

net/systemeD/potlatch2/mapfeatures/editors/Choice.as
net/systemeD/potlatch2/mapfeatures/editors/ChoiceEditorFactory.as

index 891da56499d8df9ac70fe544218160f72e021add..7e6cb37ae87506a4e4e862aa8be34e738d8f6813 100644 (file)
@@ -2,6 +2,7 @@ package net.systemeD.potlatch2.mapfeatures.editors {
 
     import flash.events.*;
     import flash.utils.ByteArray;
+    import net.systemeD.halcyon.FileBank;
 
        public class Choice extends EventDispatcher {
 
@@ -27,8 +28,10 @@ package net.systemeD.potlatch2.mapfeatures.editors {
                 _match = new RegExp("^("+matchStr+")$");
             }
         }
-    }
 
+        public function imageLoaded(fileBank:FileBank, name:String):void {
+            icon = fileBank.getAsByteArray(name);
+            dispatchEvent(new Event("iconLoaded"));
+        }        
+    }
 }
-
-
index 4cc1e0f2ca1ddb617b4d22550d9048da8027c360..16351cd2ce3e1ff7c288d31d1d9f9b49bc209d77 100644 (file)
@@ -24,10 +24,7 @@ package net.systemeD.potlatch2.mapfeatures.editors {
                 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"));
-                    });
+                    fileBank.addFromFile(icon, choice.imageLoaded);
                 }
                 choices.push(choice);
             }