Implement notComplete calls and refactor snapshotconnection a little
[potlatch2.git] / net / systemeD / potlatch2 / Preloader.as
1 package net.systemeD.potlatch2 {
2     import flash.display.DisplayObject;
3     import flash.display.GradientType;
4     import flash.display.Sprite;
5     import flash.filters.DropShadowFilter;
6     import flash.geom.Matrix;
7     import flash.text.TextField;
8     import flash.text.TextFormat;
9
10
11     public class Preloader extends net.systemeD.potlatch2.PreloaderDisplayBase {
12
13        [Embed("../../../embedded/potlatch2logo.png") ]
14         [Bindable] public var Logo:Class;
15
16         private var t:TextField;
17         private var f:DropShadowFilter=new DropShadowFilter(2,45,0x000000,0.5)
18         private var p2Logo:DisplayObject;
19         private var bar:Sprite=new Sprite();
20         private var barFrame:Sprite;
21         private var mainColor:uint=0x045966;
22
23         public function Preloader()
24         {
25             super();
26         }
27
28         // This is called when the preloader has been created as a child on the stage.
29         //  Put all real initialization here.
30         override public function initialize():void
31         {
32             super.initialize();
33
34             clear();  // clear here, rather than in draw(), to speed up the drawing
35
36             var indent:int = 20;
37             var height:int = 20;
38
39             //creates all visual elements
40             createAssets();
41         }
42         //this is our "animation" bit
43         override protected function draw():void
44         {
45             t.text = int(_fractionLoaded*100).toString()+"%";
46             //make objects below follow loading progress
47             //positions are completely arbitrary
48             //d tells us the x value of where the loading bar is at
49             var d:Number=barFrame.x + barFrame.width * _fractionLoaded
50             t.x = d - t.width - 25;
51             bar.graphics.beginFill(0xffffff,1)
52             bar.graphics.drawRoundRectComplex(0,0,bar.width * _fractionLoaded,15,12,0,0,12);
53             bar.graphics.endFill();
54         }
55
56         protected function createAssets():void
57         {
58             //create the logo
59             p2Logo = new Logo();
60             p2Logo.y = stageHeight/2 - p2Logo.height/2;
61             p2Logo.x = stageWidth/2 - p2Logo.width/2;
62             //p2Logo.filters = [f];
63             addChild(p2Logo);
64
65             //create bar
66             bar = new Sprite();
67              bar.graphics.drawRoundRectComplex(0,0,400,15,12,0,0,12);
68             bar.x = stageWidth/2 - bar.width/2;
69             bar.y = stageHeight/1.2 - bar.height/2;
70             bar.filters = [f];
71             addChild(bar);
72
73             //create bar frame
74             barFrame = new Sprite();
75             barFrame.graphics.lineStyle(2,0xFFFFFF,1)
76             barFrame.graphics.drawRoundRectComplex(0,0,400,15,12,0,0,12);
77             barFrame.graphics.endFill();
78             barFrame.x = stageWidth/2 - barFrame.width/2;
79             barFrame.y = stageHeight/1.2 - barFrame.height/2;
80             barFrame.filters = [f];
81             addChild(barFrame);
82
83             //create text field to show percentage of loading
84             t = new TextField()
85             t.y = barFrame.y-27;
86             t.filters=[f];
87             addChild(t);
88             //we can format our text
89             var s:TextFormat=new TextFormat("Verdana",null,0xFFFFFF,null,null,null,null,null,"right");
90             t.defaultTextFormat=s;
91         }
92
93         protected function clear():void
94         {
95             // Draw gradient background
96             var b:Sprite = new Sprite;
97              var matrix:Matrix =  new Matrix();
98             matrix.createGradientBox(stageWidth, stageHeight, Math.PI/2);
99             b.graphics.beginGradientFill(GradientType.LINEAR,
100                                         [mainColor, mainColor],
101                                         [1,1],
102                                         [0,255],
103                                         matrix
104                                         );
105             b.graphics.drawRect(0, 0, stageWidth, stageHeight);
106             b.graphics.endFill();
107             addChild(b);
108         }
109     }
110
111 }
112