Gratuitous animation when 100% reached
authorRichard Fairhurst <richard@systemeD.net>
Tue, 3 Jul 2012 12:36:32 +0000 (13:36 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Tue, 3 Jul 2012 12:36:32 +0000 (13:36 +0100)
embedded/zebra.png [new file with mode: 0644]
net/systemeD/potlatch2/Preloader.as
net/systemeD/potlatch2/PreloaderDisplayBase.as

diff --git a/embedded/zebra.png b/embedded/zebra.png
new file mode 100644 (file)
index 0000000..2ed8a0f
Binary files /dev/null and b/embedded/zebra.png differ
index fbf65da..c82b837 100644 (file)
@@ -2,17 +2,20 @@ package net.systemeD.potlatch2 {
     import flash.display.DisplayObject;
     import flash.display.GradientType;
     import flash.display.Sprite;
+    import flash.display.Bitmap;
+    import flash.display.BitmapData;
     import flash.filters.DropShadowFilter;
     import flash.geom.Matrix;
     import flash.text.TextField;
     import flash.text.TextFormat;
+    import flash.events.TimerEvent;
+    import flash.utils.Timer;
     import net.systemeD.halcyon.FileBank;
 
-
     public class Preloader extends net.systemeD.potlatch2.PreloaderDisplayBase {
 
-       [Embed("../../../embedded/potlatch2logo.png") ]
-        [Bindable] public var Logo:Class;
+        [Embed("../../../embedded/potlatch2logo.png") ] [Bindable] public var Logo:Class;
+        [Embed("../../../embedded/zebra.png") ] private var Zebra:Class;
 
         private var t:TextField;
         private var f:DropShadowFilter=new DropShadowFilter(2,45,0x000000,0.5)
@@ -20,6 +23,9 @@ package net.systemeD.potlatch2 {
         private var bar:Sprite=new Sprite();
         private var barFrame:Sprite;
         private var mainColor:uint=0x045966;
+        private var zebra:BitmapData;
+        private var zebraTimer:Timer;
+        private var offset:uint=0;
 
         public function Preloader()
         {
@@ -34,6 +40,9 @@ package net.systemeD.potlatch2 {
 
             clear();  // clear here, rather than in draw(), to speed up the drawing
 
+            var b:Bitmap=new Zebra();
+            zebra=new BitmapData(b.width,b.height); zebra.draw(b);
+
             var indent:int = 20;
             var height:int = 20;
 
@@ -54,18 +63,38 @@ package net.systemeD.potlatch2 {
         }
                
         //this is our "animation" bit
-        override protected function draw():void
-        {
-            t.text = _fractionLoaded==1 ? "Preparing..." : int(_fractionLoaded*100).toString()+"%";
-            //make objects below follow loading progress
-            //positions are completely arbitrary
-            //d tells us the x value of where the loading bar is at
-            var d:Number=barFrame.x + barFrame.width * _fractionLoaded
-            t.x = d - t.width - 25;
-            bar.graphics.beginFill(0xffffff,1)
-            bar.graphics.drawRoundRectComplex(0,0,bar.width * _fractionLoaded,15,12,0,0,12);
-            bar.graphics.endFill();
-        }
+               override protected function draw():void {
+                       if (_fractionLoaded==1) {
+                               if (zebraTimer) { return; }
+                               zebraTimer = new Timer(20);
+                               zebraTimer.addEventListener(TimerEvent.TIMER, zebraHandler);
+                               zebraTimer.start();
+                               t.text="Preparing...";
+                       } else {
+                               //make objects below follow loading progress
+                               //positions are completely arbitrary
+                               //d tells us the x value of where the loading bar is at
+                               bar.graphics.beginFill(0xffffff,1)
+                               bar.graphics.drawRoundRectComplex(0,0,bar.width * _fractionLoaded,15,12,0,0,12);
+                               bar.graphics.endFill();
+                               t.text = int(_fractionLoaded*100).toString()+"%";
+                       }
+                       var d:Number=barFrame.x + barFrame.width * _fractionLoaded;
+                       t.x = d - t.width - 5;
+               }
+
+               private function zebraHandler(e:Event):void {
+                       if (_IsInitComplete) {
+                               zebraTimer.stop();
+                       } else {
+                               var matrix:Matrix=new Matrix();
+                               matrix.translate(offset,0);
+                               bar.graphics.beginBitmapFill(zebra,matrix);
+                               bar.graphics.drawRoundRectComplex(0,0,bar.width,15,12,0,0,12);
+                               bar.graphics.endFill();
+                               offset=(offset+1) % 25;
+                       }
+               }
 
         protected function createAssets():void
         {
index aa93e94..aada05b 100644 (file)
@@ -38,7 +38,7 @@ package net.systemeD.potlatch2
         // This function is called when the PreloaderDisplayBase has been created and is ready for action.
         virtual public function initialize():void
         {
-            _timer = new Timer(1);
+            _timer = new Timer(20);
             _timer.addEventListener(TimerEvent.TIMER, timerHandler);
             _timer.start();
         }