home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / sky-chopper.swf / scripts / __Packages / mx / controls / Loader.as < prev    next >
Encoding:
Text File  |  2005-09-29  |  6.6 KB  |  274 lines

  1. class mx.controls.Loader extends mx.core.View
  2. {
  3.    var _origWidth;
  4.    var _origHeight;
  5.    var contentHolder;
  6.    var childrenCreated;
  7.    var __width;
  8.    var __height;
  9.    var border_mc;
  10.    static var symbolName = "Loader";
  11.    static var symbolOwner = mx.controls.Loader;
  12.    static var version = "2.0.0.360";
  13.    var className = "Loader";
  14.    var clipParameters = {autoLoad:1,scaleContent:1,contentPath:1};
  15.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.Loader.prototype.clipParameters,mx.core.View.prototype.clipParameters);
  16.    var __autoLoad = true;
  17.    var __bytesLoaded = undefined;
  18.    var __bytesTotal = undefined;
  19.    var __contentPath = undefined;
  20.    var __scaleContent = true;
  21.    function Loader()
  22.    {
  23.       super();
  24.    }
  25.    function init()
  26.    {
  27.       super.init();
  28.    }
  29.    function setSize(w, h, noEvent)
  30.    {
  31.       this._origWidth = w;
  32.       this._origHeight = h;
  33.       super.setSize(w,h,noEvent);
  34.    }
  35.    function draw()
  36.    {
  37.       this.size();
  38.    }
  39.    function size()
  40.    {
  41.       super.size();
  42.       if(this.__scaleContent)
  43.       {
  44.          this.doScaleContent();
  45.       }
  46.       else
  47.       {
  48.          this.doScaleLoader();
  49.       }
  50.    }
  51.    function createChildren()
  52.    {
  53.       super.createChildren();
  54.       if(this.__autoLoad)
  55.       {
  56.          this.load();
  57.       }
  58.    }
  59.    function getAutoLoad()
  60.    {
  61.       return this.__autoLoad;
  62.    }
  63.    function get autoLoad()
  64.    {
  65.       return this.getAutoLoad();
  66.    }
  67.    function setAutoLoad(b)
  68.    {
  69.       if(this.__autoLoad != b)
  70.       {
  71.          this.__autoLoad = b;
  72.          if(this.__autoLoad && !this[mx.core.View.childNameBase + 0]._complete)
  73.          {
  74.             this.load();
  75.          }
  76.       }
  77.    }
  78.    function set autoLoad(b)
  79.    {
  80.       this.setAutoLoad(b);
  81.    }
  82.    function getBytesLoaded()
  83.    {
  84.       return this.__bytesLoaded;
  85.    }
  86.    function get bytesLoaded()
  87.    {
  88.       return this.getBytesLoaded();
  89.    }
  90.    function getBytesTotal()
  91.    {
  92.       return this.__bytesTotal;
  93.    }
  94.    function get bytesTotal()
  95.    {
  96.       return this.getBytesTotal();
  97.    }
  98.    function getContent()
  99.    {
  100.       return this.contentHolder;
  101.    }
  102.    function get content()
  103.    {
  104.       return this.getContent();
  105.    }
  106.    function getContentPath()
  107.    {
  108.       return this.__contentPath;
  109.    }
  110.    function get contentPath()
  111.    {
  112.       return this.getContentPath();
  113.    }
  114.    function setContentPath(url)
  115.    {
  116.       if(this.__contentPath != url)
  117.       {
  118.          this.__contentPath = url;
  119.          if(this.childrenCreated)
  120.          {
  121.             if(this.__autoLoad)
  122.             {
  123.                this.load();
  124.             }
  125.          }
  126.       }
  127.    }
  128.    function set contentPath(c)
  129.    {
  130.       this.setContentPath(c);
  131.    }
  132.    function getPercentLoaded()
  133.    {
  134.       var _loc2_ = 100 * (this.__bytesLoaded / this.__bytesTotal);
  135.       if(isNaN(_loc2_))
  136.       {
  137.          _loc2_ = 0;
  138.       }
  139.       return _loc2_;
  140.    }
  141.    function get percentLoaded()
  142.    {
  143.       return this.getPercentLoaded();
  144.    }
  145.    function get scaleContent()
  146.    {
  147.       return this.getScaleContent();
  148.    }
  149.    function getScaleContent()
  150.    {
  151.       return this.__scaleContent;
  152.    }
  153.    function setScaleContent(b)
  154.    {
  155.       if(this.__scaleContent != b)
  156.       {
  157.          this.__scaleContent = b;
  158.          if(this.__scaleContent)
  159.          {
  160.             this.doScaleContent();
  161.          }
  162.          else
  163.          {
  164.             this.doScaleLoader();
  165.          }
  166.       }
  167.    }
  168.    function set scaleContent(b)
  169.    {
  170.       this.setScaleContent(b);
  171.    }
  172.    function load(url)
  173.    {
  174.       if(url != undefined)
  175.       {
  176.          this.__contentPath = url;
  177.       }
  178.       if(this[mx.core.View.childNameBase + 0] != undefined)
  179.       {
  180.          if(this[mx.core.View.childNameBase + 0]._complete)
  181.          {
  182.             this.setSize(this._origWidth,this._origHeight);
  183.          }
  184.          this.destroyChildAt(0);
  185.       }
  186.       if(this.__contentPath == undefined || this.__contentPath == "")
  187.       {
  188.          return undefined;
  189.       }
  190.       this.createChild(this.__contentPath,"contentHolder");
  191.    }
  192.    function childLoaded(obj)
  193.    {
  194.       super.childLoaded(obj);
  195.       obj._rotation = 0;
  196.       this._origWidth = this.__width;
  197.       this._origHeight = this.__height;
  198.       if(this.__scaleContent)
  199.       {
  200.          this.doScaleContent();
  201.       }
  202.       else
  203.       {
  204.          this.doScaleLoader();
  205.       }
  206.    }
  207.    function dispatchEvent(obj)
  208.    {
  209.       if(obj.type == "progress" || obj.type == "complete")
  210.       {
  211.          obj.target = this;
  212.          this.__bytesTotal = obj.total;
  213.          this.__bytesLoaded = obj.current;
  214.       }
  215.       super.dispatchEvent(obj);
  216.    }
  217.    function doScaleContent()
  218.    {
  219.       if(!this[mx.core.View.childNameBase + 0]._complete)
  220.       {
  221.          return undefined;
  222.       }
  223.       this.unScaleContent();
  224.       var _loc2_ = this.border_mc.borderMetrics;
  225.       var _loc6_ = this._origWidth - _loc2_.left - _loc2_.right;
  226.       var _loc8_ = this._origHeight - _loc2_.top - _loc2_.bottom;
  227.       var _loc9_ = _loc2_.left;
  228.       var _loc7_ = _loc2_.top;
  229.       var _loc5_ = _loc6_ / this.contentHolder._width;
  230.       var _loc3_ = _loc8_ / this.contentHolder._height;
  231.       var _loc4_ = undefined;
  232.       if(_loc5_ > _loc3_)
  233.       {
  234.          _loc9_ = _loc2_.left + Math.floor((_loc6_ - this.contentHolder._width * _loc3_) / 2);
  235.          _loc4_ = _loc3_;
  236.       }
  237.       else
  238.       {
  239.          _loc7_ = _loc2_.top + Math.floor((_loc8_ - this.contentHolder._height * _loc5_) / 2);
  240.          _loc4_ = _loc5_;
  241.       }
  242.       _loc4_ *= 100;
  243.       this.contentHolder._xscale = this.contentHolder._yscale = _loc4_;
  244.       this.contentHolder._x = _loc9_;
  245.       this.contentHolder._y = _loc7_;
  246.       if(this.__width != this._origWidth || this.__height != this._origHeight)
  247.       {
  248.          this.setSize(this._origWidth,this._origHeight);
  249.       }
  250.    }
  251.    function doScaleLoader()
  252.    {
  253.       if(!this[mx.core.View.childNameBase + 0]._complete)
  254.       {
  255.          return undefined;
  256.       }
  257.       this.unScaleContent();
  258.       var _loc2_ = this.border_mc.borderMetrics;
  259.       var _loc4_ = this.contentHolder._width + _loc2_.left + _loc2_.right;
  260.       var _loc3_ = this.contentHolder._height + _loc2_.top + _loc2_.bottom;
  261.       if(this.__width != _loc4_ || this.__height != _loc3_)
  262.       {
  263.          this.setSize(_loc4_,_loc3_);
  264.       }
  265.       this.contentHolder._x = _loc2_.left;
  266.       this.contentHolder._y = _loc2_.top;
  267.    }
  268.    function unScaleContent()
  269.    {
  270.       this.contentHolder._xscale = this.contentHolder._yscale = 100;
  271.       this.contentHolder._x = this.contentHolder._y = 0;
  272.    }
  273. }
  274.