3 import flash
.display
.DisplayObject;
4 import flash
.display
.MovieClip;
5 import flash
.display
.StageAlign;
6 import flash
.display
.StageScaleMode;
7 import flash
.events
.Event;
8 import flash
.events
.IOErrorEvent;
9 import flash
.events
.ProgressEvent;
10 import flash
.text
.TextField;
11 import flash
.text
.TextFormat;
12 import flash
.text
.TextFormatAlign;
13 import flash
.utils
.getDefinitionByName
;
19 public class Preloader
extends MovieClip
21 private var txtLoading
:TextField;
22 public function Preloader
()
25 stage
.scaleMode
= StageScaleMode.NO_SCALE
;
26 stage
.align
= StageAlign.TOP_LEFT
;
27 txtLoading
= new TextField();
28 txtLoading
.text
= "LOADING: 0%";
30 txtLoading
.width
= stage
.stageWidth
;
31 txtLoading
.height
= stage
.stageHeight
;
32 var tf
:TextFormat = new TextFormat();
35 tf
.align
= TextFormatAlign.CENTER
;
36 txtLoading
.setTextFormat
(tf
);
38 addEventListener
(Event.ENTER_FRAME
, checkFrame
);
39 loaderInfo
.addEventListener
(ProgressEvent.PROGRESS
, progress
);
40 loaderInfo
.addEventListener
(IOErrorEvent.IO_ERROR
, ioError
);
45 private function ioError
(e
:IOErrorEvent):void
50 private function progress
(e
:ProgressEvent):void
52 txtLoading
.text
= "LOADING: " + ((e
.bytesLoaded
/ e
.bytesTotal
) * 100) + "%";
55 private function checkFrame
(e
:Event):void
57 if (currentFrame
== totalFrames
)
64 private function loadingFinished
():void
66 removeEventListener
(Event.ENTER_FRAME
, checkFrame
);
67 loaderInfo
.removeEventListener
(ProgressEvent.PROGRESS
, progress
);
68 loaderInfo
.removeEventListener
(IOErrorEvent.IO_ERROR
, ioError
);
70 removeChild
(txtLoading
);
75 private function startup
():void
77 var mainClass
:Class = getDefinitionByName
("Main") as Class;
78 addChild
(new mainClass
() as DisplayObject);