home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / zombietypocalypse.swf / scripts / classes / components / FG_Preloader.as < prev    next >
Encoding:
Text File  |  2008-09-15  |  2.9 KB  |  101 lines

  1. package classes.components
  2. {
  3.    import classes.dispatchers.GameDispatcher;
  4.    import classes.graphical.information.bars.ProgresBar;
  5.    import flash.display.MovieClip;
  6.    import flash.events.Event;
  7.    import flash.events.ProgressEvent;
  8.    import flash.text.TextField;
  9.    
  10.    public class FG_Preloader extends MovieClip
  11.    {
  12.        
  13.       
  14.       private var _percents:TextField;
  15.       
  16.       private var _elements:Array;
  17.       
  18.       private var _weight:TextField;
  19.       
  20.       private var _progresBar:ProgresBar;
  21.       
  22.       public function FG_Preloader()
  23.       {
  24.          super();
  25.          this._elements = new Array();
  26.          this._percents = TextField(this.getChildByName("percent"));
  27.          if(this._percents != null)
  28.          {
  29.             this._elements[0] = true;
  30.          }
  31.          this._weight = TextField(this.getChildByName("weight_txt"));
  32.          if(this._weight != null)
  33.          {
  34.             this._elements[1] = true;
  35.          }
  36.          this._progresBar = ProgresBar(this.getChildByName("_progresBarTimeline"));
  37.          if(this._progresBar != null)
  38.          {
  39.             this._elements[2] = true;
  40.          }
  41.       }
  42.       
  43.       private function progressListener(param1:ProgressEvent) : void
  44.       {
  45.          var _loc2_:Number = NaN;
  46.          var _loc3_:int = 0;
  47.          _loc2_ = param1.bytesLoaded / param1.bytesTotal;
  48.          _loc3_ = _loc2_ * 100;
  49.          if(this._elements[0])
  50.          {
  51.             this._percents.text = String(_loc3_ + "%");
  52.          }
  53.          if(this._elements[1])
  54.          {
  55.             this._weight.text = String(int(param1.bytesTotal / 1024) + " kB");
  56.          }
  57.          if(this._elements[2])
  58.          {
  59.             this._progresBar.setProgres(_loc3_);
  60.          }
  61.       }
  62.       
  63.       private function completeListener(param1:Event) : void
  64.       {
  65.          this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS,progressListener);
  66.          this.loaderInfo.removeEventListener(Event.COMPLETE,completeListener);
  67.          this.finishLoading();
  68.       }
  69.       
  70.       private function finishLoading() : void
  71.       {
  72.          if(this._elements[0])
  73.          {
  74.             this._percents.text = String(100 + "%");
  75.          }
  76.          if(this._elements[1])
  77.          {
  78.             this._weight.text = String(int(this.loaderInfo.bytesTotal / 1024) + " kB");
  79.          }
  80.          if(this._elements[2])
  81.          {
  82.             this._progresBar.setProgres(100);
  83.          }
  84.          GameDispatcher.preloaderDispatcher.loadingComplete();
  85.       }
  86.       
  87.       public function startLoad() : void
  88.       {
  89.          if(this.loaderInfo.bytesLoaded >= this.loaderInfo.bytesTotal)
  90.          {
  91.             this.finishLoading();
  92.          }
  93.          else
  94.          {
  95.             this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,progressListener);
  96.             this.loaderInfo.addEventListener(Event.COMPLETE,completeListener);
  97.          }
  98.       }
  99.    }
  100. }
  101.