home *** CD-ROM | disk | FTP | other *** search
- package classes.components
- {
- import classes.dispatchers.GameDispatcher;
- import classes.graphical.information.bars.ProgresBar;
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.ProgressEvent;
- import flash.text.TextField;
-
- public class FG_Preloader extends MovieClip
- {
-
-
- private var _percents:TextField;
-
- private var _elements:Array;
-
- private var _weight:TextField;
-
- private var _progresBar:ProgresBar;
-
- public function FG_Preloader()
- {
- super();
- this._elements = new Array();
- this._percents = TextField(this.getChildByName("percent"));
- if(this._percents != null)
- {
- this._elements[0] = true;
- }
- this._weight = TextField(this.getChildByName("weight_txt"));
- if(this._weight != null)
- {
- this._elements[1] = true;
- }
- this._progresBar = ProgresBar(this.getChildByName("_progresBarTimeline"));
- if(this._progresBar != null)
- {
- this._elements[2] = true;
- }
- }
-
- private function progressListener(param1:ProgressEvent) : void
- {
- var _loc2_:Number = NaN;
- var _loc3_:int = 0;
- _loc2_ = param1.bytesLoaded / param1.bytesTotal;
- _loc3_ = _loc2_ * 100;
- if(this._elements[0])
- {
- this._percents.text = String(_loc3_ + "%");
- }
- if(this._elements[1])
- {
- this._weight.text = String(int(param1.bytesTotal / 1024) + " kB");
- }
- if(this._elements[2])
- {
- this._progresBar.setProgres(_loc3_);
- }
- }
-
- private function completeListener(param1:Event) : void
- {
- this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS,progressListener);
- this.loaderInfo.removeEventListener(Event.COMPLETE,completeListener);
- this.finishLoading();
- }
-
- private function finishLoading() : void
- {
- if(this._elements[0])
- {
- this._percents.text = String(100 + "%");
- }
- if(this._elements[1])
- {
- this._weight.text = String(int(this.loaderInfo.bytesTotal / 1024) + " kB");
- }
- if(this._elements[2])
- {
- this._progresBar.setProgres(100);
- }
- GameDispatcher.preloaderDispatcher.loadingComplete();
- }
-
- public function startLoad() : void
- {
- if(this.loaderInfo.bytesLoaded >= this.loaderInfo.bytesTotal)
- {
- this.finishLoading();
- }
- else
- {
- this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,progressListener);
- this.loaderInfo.addEventListener(Event.COMPLETE,completeListener);
- }
- }
- }
- }
-