home *** CD-ROM | disk | FTP | other *** search
/ Digital Background Bonanza / Digital Background Bonanza - Disc 1.iso / pc / DBB1.swf / scripts / __Packages / mx / controls / Loader.as < prev    next >
Encoding:
Text File  |  2007-03-09  |  7.0 KB  |  286 lines

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