Load choice editor images through the FileBank
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / ChoiceEditorFactory.as
1 package net.systemeD.potlatch2.mapfeatures.editors {
2
3     import net.systemeD.halcyon.connection.*;
4     import net.systemeD.potlatch2.mapfeatures.*;
5     import net.systemeD.halcyon.FileBank;
6     import flash.display.*;
7     import flash.events.*;
8
9         public class ChoiceEditorFactory extends SingleTagEditorFactory {
10             public var choices:Array;
11         
12         public function ChoiceEditorFactory(inputXML:XML) {
13             super(inputXML,"horizontal");
14             
15             choices = [];
16
17             var fileBank:FileBank = FileBank.getInstance();
18             
19             for each( var choiceXML:XML in inputXML.choice ) {
20                 var choice:Choice = new Choice();
21                 choice.value = String(choiceXML.@value);
22                 choice.description = String(choiceXML.@description);
23                 choice.label = String(choiceXML.@text);
24                 choice.match = String(choiceXML.@match);
25                 if (choiceXML.hasOwnProperty("@icon")) {
26                     var icon:String = String(choiceXML.@icon);
27                     fileBank.addFromFile(icon, function (fb:FileBank, name:String):void {
28                         choice.icon = fb.getAsByteArray(name);
29                         choice.dispatchEvent(new Event("iconLoaded"));
30                     });
31                 }
32                 choices.push(choice);
33             }
34         }
35         
36         override protected function createSingleTagEditor():SingleTagEditor {
37             return new ChoiceEditor();
38         }
39     }
40
41 }
42
43