home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Swf / Essenciais.swf / scripts / __Packages / com / rightactionscript / fcb / components / Loader.as next >
Encoding:
Text File  |  2010-02-24  |  5.3 KB  |  201 lines

  1. class com.rightactionscript.fcb.components.Loader extends com.rightactionscript.fcb.components.UIBasicComponent
  2. {
  3.    var _bAutoLoad;
  4.    var _bScaleContent;
  5.    var _sURL;
  6.    var _nBytesLoaded;
  7.    var _nBytesTotal;
  8.    var _mcHolder;
  9.    var _bInited;
  10.    var __width;
  11.    var __height;
  12.    var _bLoading;
  13.    var _sPrevURL;
  14.    var _mcFrame;
  15.    var _mcMask;
  16.    var _nPrevLoaded;
  17.    var _nInterval;
  18.    var dispatchEvent;
  19.    var _bDoFade = false;
  20.    var _bDrawFrame = false;
  21.    var _oDimensions = null;
  22.    var _nRoundCorners = 0;
  23.    var _bLoaded = false;
  24.    function Loader()
  25.    {
  26.       super();
  27.       this._bAutoLoad = true;
  28.    }
  29.    function set scaleContent(bScaleContent)
  30.    {
  31.       this._bScaleContent = bScaleContent;
  32.    }
  33.    function get scaleContent()
  34.    {
  35.       return this._bScaleContent;
  36.    }
  37.    function set autoLoad(bAutoLoad)
  38.    {
  39.       this._bAutoLoad = bAutoLoad;
  40.    }
  41.    function get autoLoad()
  42.    {
  43.       return this._bAutoLoad;
  44.    }
  45.    function set contentPath(sURL)
  46.    {
  47.       this._sURL = sURL;
  48.       if(this._bAutoLoad)
  49.       {
  50.          this.load();
  51.       }
  52.    }
  53.    function get bytesLoaded()
  54.    {
  55.       return this._nBytesLoaded;
  56.    }
  57.    function get bytesTotal()
  58.    {
  59.       return this._nBytesTotal;
  60.    }
  61.    function get percentLoaded()
  62.    {
  63.       var _loc2_ = Math.round(this.bytesLoaded / this.bytesTotal * 100);
  64.       _loc2_ = !isNaN(_loc2_) ? _loc2_ : 0;
  65.       return _loc2_;
  66.    }
  67.    function get content()
  68.    {
  69.       return this._mcHolder.mcContent;
  70.    }
  71.    function init()
  72.    {
  73.       super.init();
  74.       if(this._bScaleContent == undefined)
  75.       {
  76.          this._bScaleContent = true;
  77.       }
  78.       this._bInited = true;
  79.       this._nBytesLoaded = 0;
  80.       this._nBytesTotal = 0;
  81.    }
  82.    function createChildren()
  83.    {
  84.       this.createEmptyMovieClip("_mcHolder",this.getNextHighestDepth());
  85.       this.createEmptyMovieClip("_mcFrame",this.getNextHighestDepth());
  86.       this.createEmptyMovieClip("_mcMask",this.getNextHighestDepth());
  87.       if(this._bAutoLoad && this._sURL != undefined)
  88.       {
  89.          this.load();
  90.       }
  91.    }
  92.    function size()
  93.    {
  94.       this._xscale = 100;
  95.       this._yscale = 100;
  96.       if(this._bScaleContent)
  97.       {
  98.          var _loc5_ = this._mcHolder.mcContent._width;
  99.          var _loc4_ = this._mcHolder.mcContent._height;
  100.          var _loc2_ = _loc5_ / _loc4_;
  101.          var _loc3_ = this.__width / this.__height;
  102.          if(_loc2_ == _loc3_)
  103.          {
  104.             this._mcHolder._width = this.__width;
  105.             this._mcHolder._height = this.__height;
  106.          }
  107.          else if(_loc2_ > _loc3_)
  108.          {
  109.             this._mcHolder._width = this.__width;
  110.             this._mcHolder._height = this.__width / _loc2_;
  111.          }
  112.          else
  113.          {
  114.             this._mcHolder._width = this.__height * _loc2_;
  115.             this._mcHolder._height = this.__height;
  116.          }
  117.       }
  118.       else if(this._mcHolder.mcContent._width != undefined)
  119.       {
  120.          this._mcHolder._width = this._mcHolder.mcContent._width;
  121.          this._mcHolder._height = this._mcHolder.mcContent._height;
  122.       }
  123.    }
  124.    function load()
  125.    {
  126.       if(this._bLoading && this._sPrevURL == this._sURL || this._sURL == undefined || this._sURL == "" || this._mcHolder == undefined)
  127.       {
  128.          return undefined;
  129.       }
  130.       this._visible = false;
  131.       this._bLoaded = false;
  132.       this._bLoading = true;
  133.       this._sPrevURL = this._sURL;
  134.       this._mcHolder.mcContent.removeMovieClip();
  135.       this._mcFrame.clear();
  136.       this._mcMask.clear();
  137.       this._mcHolder.attachMovie(this._sURL,"mcContent",1);
  138.       if(this._mcHolder.mcContent == undefined)
  139.       {
  140.          this._mcHolder.mcContent.removeMovieClip();
  141.          this._mcHolder.createEmptyMovieClip("mcContent",1);
  142.          this._mcHolder.mcContent.loadMovie(this._sURL);
  143.          this._nPrevLoaded = 0;
  144.          this._nInterval = setInterval(this,"checkLoadProgress",50);
  145.       }
  146.       else
  147.       {
  148.          this.onLoadInit();
  149.       }
  150.    }
  151.    function onLoadProgress(mc, bl, bt)
  152.    {
  153.       this._nBytesLoaded = bl;
  154.       this._nBytesTotal = bt;
  155.       this.dispatchEvent({type:"progress",target:this});
  156.    }
  157.    function onLoadInit()
  158.    {
  159.       this._bLoaded = true;
  160.       this._bLoading = false;
  161.       this.size();
  162.       this._visible = true;
  163.       this.dispatchEvent({type:"complete",target:this});
  164.    }
  165.    function checkLoadProgress()
  166.    {
  167.       var _loc2_ = this._mcHolder.mcContent.getBytesLoaded();
  168.       var _loc3_ = this._mcHolder.mcContent.getBytesTotal();
  169.       if(_loc2_ > this._nPrevLoaded)
  170.       {
  171.          this.onLoadProgress(this._mcHolder.mcContent,_loc2_,_loc3_);
  172.          this._nPrevLoaded = _loc2_;
  173.       }
  174.       if(_loc2_ / _loc3_ == 1 && this._mcHolder.mcContent._width != 0)
  175.       {
  176.          this.onLoadInit();
  177.          clearInterval(this._nInterval);
  178.       }
  179.    }
  180.    function get loaded()
  181.    {
  182.       return this._bLoaded;
  183.    }
  184.    function set dimensions(oDimensions)
  185.    {
  186.       this._oDimensions = oDimensions;
  187.    }
  188.    function set drawFrame(bDrawFrame)
  189.    {
  190.       this._bDrawFrame = bDrawFrame;
  191.    }
  192.    function set doFade(bDoFade)
  193.    {
  194.       this._bDoFade = bDoFade;
  195.    }
  196.    function set roundcorners(nRoundCorners)
  197.    {
  198.       this._nRoundCorners = nRoundCorners;
  199.    }
  200. }
  201.