ImageBank->FileBank
[potlatch2.git] / net / systemeD / potlatch2 / Preloader.as
index 1014c0a3f6810fb1247708b5f92538c86f1ba74f..3b2c9c83859dae6c56feb1069c6f0f0893a78881 100644 (file)
@@ -6,6 +6,7 @@ package net.systemeD.potlatch2 {
     import flash.geom.Matrix;
     import flash.text.TextField;
     import flash.text.TextFormat;
+    import net.systemeD.halcyon.FileBank;
 
 
     public class Preloader extends net.systemeD.potlatch2.PreloaderDisplayBase {
@@ -20,6 +21,9 @@ package net.systemeD.potlatch2 {
         private var barFrame:Sprite;
         private var mainColor:uint=0x045966;
 
+               private var assetscount:uint=0;
+               private var queuedEvents:Array=[];
+
         public function Preloader()
         {
             super();
@@ -38,7 +42,35 @@ package net.systemeD.potlatch2 {
 
             //creates all visual elements
             createAssets();
+
+                       // request .zip files
+                       if (loaderInfo.parameters['assets']) {
+                               FileBank.getInstance().addEventListener(FileBank.ZIP_LOADED, zipLoaded);
+                               for each (var file:String in loaderInfo.parameters['assets'].split(';')) {
+                                       var asset:Array=file.split('=');
+                                       assetscount++;
+                                       FileBank.getInstance().addFromZip(asset[0],asset[1]);
+                               }
+                       }
         }
+
+               override protected function initProgressHandler(e:Event):void {
+                       // We don't let anything happen until the .zips are loaded
+                       // see http://stackoverflow.com/questions/2773617/how-to-preload-a-file-in-flex-before-the-application-initializes
+                       if (assetscount>0) {
+                               queuedEvents.push(e);
+                               e.stopImmediatePropagation();
+                       }
+                       draw();
+               }
+               
+               private function zipLoaded(e:Event):void {
+                       assetscount--; if (assetscount>0) return;
+                       for each (var q:Event in queuedEvents) {
+                               dispatchEvent(q);
+                       }
+               }
+               
         //this is our "animation" bit
         override protected function draw():void
         {