Fix hair, dick around with new game screen.
[18plus-7leafadventure.git] / src / Preloader.as
blob41df44863b776b65938b414e588c32c1ec0220a1
1 package
3 import flash.display.*;
4 import flash.text.*;
5 import flash.utils.*;
6 import flash.events.*;
7 import flash.net.*;
8 import mx.events.FlexEvent;
9 import mx.preloaders.*;
10 import mx.preloaders.IPreloaderDisplay;
11 import flash.filters.GlowFilter;
13 /**
14 * ...
15 * @author Rob
17 public class Preloader extends Sprite implements IPreloaderDisplay
19 private var txtLoading:TextField;
20 private var graphicLoader:Sprite = new Sprite();
21 private var bgcolor:Sprite = new Sprite();
22 private var c:Number = 0; // angle.
23 private var percentDone:Number = 0;
25 public function Preloader()
27 super();
28 if (stage)
33 // Specify the event listeners.
34 public function set preloader(preloader:Sprite):void
36 // Listen for the relevant events
37 preloader.addEventListener(Event.ENTER_FRAME, onFrame);
38 preloader.addEventListener(ProgressEvent.PROGRESS, handleProgress);
39 preloader.addEventListener(Event.COMPLETE, handleComplete);
40 preloader.addEventListener(FlexEvent.INIT_PROGRESS, handleInitProgress);
41 //preloader.addEventListener(FlexEvent.INIT_COMPLETE, handleInitComplete);
44 // Initialize the Loader control in the override
45 // of IPreloaderDisplay.initialize().
46 public function initialize():void
48 //stage.scaleMode = StageScaleMode.NO_SCALE;
49 //stage.align = StageAlign.TOP_LEFT;
51 // Background
52 bgcolor.graphics.clear();
53 bgcolor.graphics.beginFill(0x000000, 1);
54 bgcolor.graphics.drawRect(0, 0, stageWidth, stageHeight);
55 addChildAt(bgcolor, 0);
57 // Circular Loader
58 addChild(graphicLoader);
59 graphicLoader.width = stage.stageWidth;
60 graphicLoader.height = stage.stageHeight;
61 graphicLoader.x = 0;
62 graphicLoader.y = 0;
63 stage.addEventListener(Event.RESIZE, resizeBGWithStage);
65 txtLoading = new TextField();
66 txtLoading.text = "0%";
67 addChild(txtLoading);
68 var tf:TextFormat = new TextFormat();
69 tf.font = "Arial";
70 tf.size = "22";
71 txtLoading.setTextFormat(tf);
72 txtLoading.textColor = 0xffffff;
75 private function onFrame(e:Event):void
77 draw();
80 private function resizeBGWithStage(e:Event):void
82 try
84 bgcolor.width = stageWidth;
85 bgcolor.height = stageHeight;
86 bgcolor.graphics.beginFill(0x000000, 1);
87 bgcolor.graphics.drawRect(0, 0, stageWidth, stageHeight);
89 graphicLoader.x = 0;
90 graphicLoader.y = 0;
91 graphicLoader.width = stageWidth;
92 graphicLoader.height = stageHeight;
94 txtLoading.x = (stageWidth / 2) - (txtLoading.width / 2);
95 txtLoading.y = (stageHeight / 2) - (txtLoading.height / 2);
97 catch (e:*)
102 private function handleProgress(e:ProgressEvent):void
104 txtLoading.text = ((e.bytesLoaded / e.bytesTotal) * 100) + "%";
105 draw();
106 c = Math.round((e.bytesLoaded / e.bytesTotal) * 100 * (-1.84));
109 private function draw():void {
112 var glow:GlowFilter = new GlowFilter();
113 glow.color = 0xffffff;
114 glow.alpha = 1;
115 glow.blurX = 25;
116 glow.blurY = 25;
118 graphicLoader.graphics.clear();
120 graphicLoader.graphics.lineStyle(1, 0xffffff, 1);
121 var center_x:Number = stage.stageWidth / 2;
122 var center_y:Number = stage.stageHeight / 2;
123 graphicLoader.graphics.moveTo(center_x, center_y);
124 var fp:Boolean = false;
125 for (var i:Number = 0; i >= c; i--)
127 x = Math.sin(Math.PI / 90 * i) * 100 + center_x;
128 y = Math.cos(Math.PI / 90 * i) * 100 + center_y;
129 graphicLoader.graphics.lineTo(x, y);
132 graphicLoader.filters = new Array(glow);
135 private function handleComplete(event:Event):void
137 //loadingFinished();
140 private function handleInitProgress(event:Event):void
144 private function ioError(e:IOErrorEvent):void
146 trace(e.text);
149 private function progress(e:ProgressEvent):void
153 private function loadingFinished():void
155 //removeEventListener(Event.ENTER_FRAME, checkFrame);
156 loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
157 loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
159 removeChild(txtLoading);
161 startup();
164 private function startup():void
166 var mainClass:Class = getDefinitionByName("Main") as Class;
167 addChild(new mainClass() as DisplayObject);
168 } // Implement IPreloaderDisplay interface
170 public function get backgroundColor():uint
172 return 0x000000;
175 public function set backgroundColor(value:uint):void
179 public function get backgroundAlpha():Number
181 return 1;
184 public function set backgroundAlpha(value:Number):void
188 public function get backgroundImage():Object
190 return undefined;
193 public function set backgroundImage(value:Object):void
197 public function get backgroundSize():String
199 return "";
202 public function set backgroundSize(value:String):void
206 public function get stageWidth():Number
208 return 800;
211 public function set stageWidth(value:Number):void
215 public function get stageHeight():Number
217 return 600;
220 public function set stageHeight(value:Number):void