home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Swf / Internet.swf / scripts / __Packages / mx / managers / DepthManager.as next >
Encoding:
Text File  |  2010-02-23  |  13.7 KB  |  462 lines

  1. class mx.managers.DepthManager
  2. {
  3.    var _childCounter;
  4.    var createClassObject;
  5.    var createObject;
  6.    var _parent;
  7.    var swapDepths;
  8.    var _topmost;
  9.    var getDepth;
  10.    static var reservedDepth = 1048575;
  11.    static var highestDepth = 1048574;
  12.    static var lowestDepth = -16383;
  13.    static var numberOfAuthortimeLayers = 383;
  14.    static var kCursor = 101;
  15.    static var kTooltip = 102;
  16.    static var kTop = 201;
  17.    static var kBottom = 202;
  18.    static var kTopmost = 203;
  19.    static var kNotopmost = 204;
  20.    static var holder = _root.createEmptyMovieClip("reserved",mx.managers.DepthManager.reservedDepth);
  21.    static var __depthManager = new mx.managers.DepthManager();
  22.    function DepthManager()
  23.    {
  24.       MovieClip.prototype.createClassChildAtDepth = this.createClassChildAtDepth;
  25.       MovieClip.prototype.createChildAtDepth = this.createChildAtDepth;
  26.       MovieClip.prototype.setDepthTo = this.setDepthTo;
  27.       MovieClip.prototype.setDepthAbove = this.setDepthAbove;
  28.       MovieClip.prototype.setDepthBelow = this.setDepthBelow;
  29.       MovieClip.prototype.findNextAvailableDepth = this.findNextAvailableDepth;
  30.       MovieClip.prototype.shuffleDepths = this.shuffleDepths;
  31.       MovieClip.prototype.getDepthByFlag = this.getDepthByFlag;
  32.       MovieClip.prototype.buildDepthTable = this.buildDepthTable;
  33.    }
  34.    static function sortFunction(a, b)
  35.    {
  36.       if(a.getDepth() > b.getDepth())
  37.       {
  38.          return 1;
  39.       }
  40.       return -1;
  41.    }
  42.    static function test(depth)
  43.    {
  44.       if(depth == mx.managers.DepthManager.reservedDepth)
  45.       {
  46.          return false;
  47.       }
  48.       return true;
  49.    }
  50.    static function createClassObjectAtDepth(className, depthSpace, initObj)
  51.    {
  52.       var _loc1_ = undefined;
  53.       switch(depthSpace)
  54.       {
  55.          case mx.managers.DepthManager.kCursor:
  56.             _loc1_ = mx.managers.DepthManager.holder.createClassChildAtDepth(className,mx.managers.DepthManager.kTopmost,initObj);
  57.             break;
  58.          case mx.managers.DepthManager.kTooltip:
  59.             _loc1_ = mx.managers.DepthManager.holder.createClassChildAtDepth(className,mx.managers.DepthManager.kTop,initObj);
  60.       }
  61.       return _loc1_;
  62.    }
  63.    static function createObjectAtDepth(linkageName, depthSpace, initObj)
  64.    {
  65.       var _loc1_ = undefined;
  66.       switch(depthSpace)
  67.       {
  68.          case mx.managers.DepthManager.kCursor:
  69.             _loc1_ = mx.managers.DepthManager.holder.createChildAtDepth(linkageName,mx.managers.DepthManager.kTopmost,initObj);
  70.             break;
  71.          case mx.managers.DepthManager.kTooltip:
  72.             _loc1_ = mx.managers.DepthManager.holder.createChildAtDepth(linkageName,mx.managers.DepthManager.kTop,initObj);
  73.       }
  74.       return _loc1_;
  75.    }
  76.    function createClassChildAtDepth(className, depthFlag, initObj)
  77.    {
  78.       if(this._childCounter == undefined)
  79.       {
  80.          this._childCounter = 0;
  81.       }
  82.       var _loc3_ = this.buildDepthTable();
  83.       var _loc2_ = this.getDepthByFlag(depthFlag,_loc3_);
  84.       var _loc5_ = "down";
  85.       if(depthFlag == mx.managers.DepthManager.kBottom)
  86.       {
  87.          _loc5_ = "up";
  88.       }
  89.       var _loc6_ = undefined;
  90.       if(_loc3_[_loc2_] != undefined)
  91.       {
  92.          _loc6_ = _loc2_;
  93.          _loc2_ = this.findNextAvailableDepth(_loc2_,_loc3_,_loc5_);
  94.       }
  95.       var _loc4_ = this.createClassObject(className,"depthChild" + this._childCounter++,_loc2_,initObj);
  96.       if(_loc6_ != undefined)
  97.       {
  98.          _loc3_[_loc2_] = _loc4_;
  99.          this.shuffleDepths(_loc4_,_loc6_,_loc3_,_loc5_);
  100.       }
  101.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  102.       {
  103.          _loc4_._topmost = true;
  104.       }
  105.       return _loc4_;
  106.    }
  107.    function createChildAtDepth(linkageName, depthFlag, initObj)
  108.    {
  109.       if(this._childCounter == undefined)
  110.       {
  111.          this._childCounter = 0;
  112.       }
  113.       var _loc3_ = this.buildDepthTable();
  114.       var _loc2_ = this.getDepthByFlag(depthFlag,_loc3_);
  115.       var _loc5_ = "down";
  116.       if(depthFlag == mx.managers.DepthManager.kBottom)
  117.       {
  118.          _loc5_ = "up";
  119.       }
  120.       var _loc6_ = undefined;
  121.       if(_loc3_[_loc2_] != undefined)
  122.       {
  123.          _loc6_ = _loc2_;
  124.          _loc2_ = this.findNextAvailableDepth(_loc2_,_loc3_,_loc5_);
  125.       }
  126.       var _loc4_ = this.createObject(linkageName,"depthChild" + this._childCounter++,_loc2_,initObj);
  127.       if(_loc6_ != undefined)
  128.       {
  129.          _loc3_[_loc2_] = _loc4_;
  130.          this.shuffleDepths(_loc4_,_loc6_,_loc3_,_loc5_);
  131.       }
  132.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  133.       {
  134.          _loc4_._topmost = true;
  135.       }
  136.       return _loc4_;
  137.    }
  138.    function setDepthTo(depthFlag)
  139.    {
  140.       var _loc2_ = this._parent.buildDepthTable();
  141.       var _loc3_ = this._parent.getDepthByFlag(depthFlag,_loc2_);
  142.       if(_loc2_[_loc3_] != undefined)
  143.       {
  144.          this.shuffleDepths(MovieClip(this),_loc3_,_loc2_,undefined);
  145.       }
  146.       else
  147.       {
  148.          this.swapDepths(_loc3_);
  149.       }
  150.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  151.       {
  152.          this._topmost = true;
  153.       }
  154.       else
  155.       {
  156.          delete this._topmost;
  157.       }
  158.    }
  159.    function setDepthAbove(targetInstance)
  160.    {
  161.       if(targetInstance._parent != this._parent)
  162.       {
  163.          return undefined;
  164.       }
  165.       var _loc2_ = targetInstance.getDepth() + 1;
  166.       var _loc3_ = this._parent.buildDepthTable();
  167.       if(_loc3_[_loc2_] != undefined && this.getDepth() < _loc2_)
  168.       {
  169.          _loc2_ -= 1;
  170.       }
  171.       if(_loc2_ > mx.managers.DepthManager.highestDepth)
  172.       {
  173.          _loc2_ = mx.managers.DepthManager.highestDepth;
  174.       }
  175.       if(_loc2_ == mx.managers.DepthManager.highestDepth)
  176.       {
  177.          this._parent.shuffleDepths(this,_loc2_,_loc3_,"down");
  178.       }
  179.       else if(_loc3_[_loc2_] != undefined)
  180.       {
  181.          this._parent.shuffleDepths(this,_loc2_,_loc3_,undefined);
  182.       }
  183.       else
  184.       {
  185.          this.swapDepths(_loc2_);
  186.       }
  187.    }
  188.    function setDepthBelow(targetInstance)
  189.    {
  190.       if(targetInstance._parent != this._parent)
  191.       {
  192.          return undefined;
  193.       }
  194.       var _loc6_ = targetInstance.getDepth() - 1;
  195.       var _loc3_ = this._parent.buildDepthTable();
  196.       if(_loc3_[_loc6_] != undefined && this.getDepth() > _loc6_)
  197.       {
  198.          _loc6_ += 1;
  199.       }
  200.       var _loc4_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  201.       var _loc5_ = undefined;
  202.       for(_loc5_ in _loc3_)
  203.       {
  204.          var _loc2_ = _loc3_[_loc5_];
  205.          if(_loc2_._parent != undefined)
  206.          {
  207.             _loc4_ = Math.min(_loc4_,_loc2_.getDepth());
  208.          }
  209.       }
  210.       if(_loc6_ < _loc4_)
  211.       {
  212.          _loc6_ = _loc4_;
  213.       }
  214.       if(_loc6_ == _loc4_)
  215.       {
  216.          this._parent.shuffleDepths(this,_loc6_,_loc3_,"up");
  217.       }
  218.       else if(_loc3_[_loc6_] != undefined)
  219.       {
  220.          this._parent.shuffleDepths(this,_loc6_,_loc3_,undefined);
  221.       }
  222.       else
  223.       {
  224.          this.swapDepths(_loc6_);
  225.       }
  226.    }
  227.    function findNextAvailableDepth(targetDepth, depthTable, direction)
  228.    {
  229.       var _loc5_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  230.       if(targetDepth < _loc5_)
  231.       {
  232.          targetDepth = _loc5_;
  233.       }
  234.       if(depthTable[targetDepth] == undefined)
  235.       {
  236.          return targetDepth;
  237.       }
  238.       var _loc1_ = targetDepth;
  239.       var _loc2_ = targetDepth;
  240.       if(direction == "down")
  241.       {
  242.          while(depthTable[_loc2_] != undefined)
  243.          {
  244.             _loc2_ = _loc2_ - 1;
  245.          }
  246.          return _loc2_;
  247.       }
  248.       while(depthTable[_loc1_] != undefined)
  249.       {
  250.          _loc1_ = _loc1_ + 1;
  251.       }
  252.       return _loc1_;
  253.    }
  254.    function shuffleDepths(subject, targetDepth, depthTable, direction)
  255.    {
  256.       var _loc9_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  257.       var _loc8_ = _loc9_;
  258.       var _loc5_ = undefined;
  259.       for(_loc5_ in depthTable)
  260.       {
  261.          var _loc7_ = depthTable[_loc5_];
  262.          if(_loc7_._parent != undefined)
  263.          {
  264.             _loc9_ = Math.min(_loc9_,_loc7_.getDepth());
  265.          }
  266.       }
  267.       if(direction == undefined)
  268.       {
  269.          if(subject.getDepth() > targetDepth)
  270.          {
  271.             direction = "up";
  272.          }
  273.          else
  274.          {
  275.             direction = "down";
  276.          }
  277.       }
  278.       var _loc1_ = new Array();
  279.       for(_loc5_ in depthTable)
  280.       {
  281.          _loc7_ = depthTable[_loc5_];
  282.          if(_loc7_._parent != undefined)
  283.          {
  284.             _loc1_.push(_loc7_);
  285.          }
  286.       }
  287.       _loc1_.sort(mx.managers.DepthManager.sortFunction);
  288.       if(direction == "up")
  289.       {
  290.          var _loc3_ = undefined;
  291.          var _loc11_ = undefined;
  292.          while(_loc1_.length > 0)
  293.          {
  294.             _loc3_ = _loc1_.pop();
  295.             if(_loc3_ == subject)
  296.             {
  297.                break;
  298.             }
  299.          }
  300.          while(_loc1_.length > 0)
  301.          {
  302.             _loc11_ = subject.getDepth();
  303.             _loc3_ = _loc1_.pop();
  304.             var _loc4_ = _loc3_.getDepth();
  305.             if(_loc11_ > _loc4_ + 1)
  306.             {
  307.                if(_loc4_ >= 0)
  308.                {
  309.                   subject.swapDepths(_loc4_ + 1);
  310.                }
  311.                else if(_loc11_ > _loc8_ && _loc4_ < _loc8_)
  312.                {
  313.                   subject.swapDepths(_loc8_);
  314.                }
  315.             }
  316.             subject.swapDepths(_loc3_);
  317.             if(_loc4_ == targetDepth)
  318.             {
  319.                break;
  320.             }
  321.          }
  322.       }
  323.       else if(direction == "down")
  324.       {
  325.          _loc3_ = undefined;
  326.          while(_loc1_.length > 0)
  327.          {
  328.             _loc3_ = _loc1_.shift();
  329.             if(_loc3_ == subject)
  330.             {
  331.                break;
  332.             }
  333.          }
  334.          while(_loc1_.length > 0)
  335.          {
  336.             _loc11_ = _loc3_.getDepth();
  337.             _loc3_ = _loc1_.shift();
  338.             _loc4_ = _loc3_.getDepth();
  339.             if(_loc11_ < _loc4_ - 1 && _loc4_ > 0)
  340.             {
  341.                subject.swapDepths(_loc4_ - 1);
  342.             }
  343.             subject.swapDepths(_loc3_);
  344.             if(_loc4_ == targetDepth)
  345.             {
  346.                break;
  347.             }
  348.          }
  349.       }
  350.    }
  351.    function getDepthByFlag(depthFlag, depthTable)
  352.    {
  353.       var _loc2_ = 0;
  354.       if(depthFlag == mx.managers.DepthManager.kTop || depthFlag == mx.managers.DepthManager.kNotopmost)
  355.       {
  356.          var _loc5_ = 0;
  357.          var _loc7_ = false;
  358.          var _loc8_ = undefined;
  359.          for(_loc8_ in depthTable)
  360.          {
  361.             var _loc9_ = depthTable[_loc8_];
  362.             var _loc3_ = typeof _loc9_;
  363.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  364.             {
  365.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  366.                {
  367.                   if(!_loc9_._topmost)
  368.                   {
  369.                      _loc2_ = Math.max(_loc2_,_loc9_.getDepth());
  370.                   }
  371.                   else if(!_loc7_)
  372.                   {
  373.                      _loc5_ = _loc9_.getDepth();
  374.                      _loc7_ = true;
  375.                   }
  376.                   else
  377.                   {
  378.                      _loc5_ = Math.min(_loc5_,_loc9_.getDepth());
  379.                   }
  380.                }
  381.             }
  382.          }
  383.          _loc2_ += 20;
  384.          if(_loc7_)
  385.          {
  386.             if(_loc2_ >= _loc5_)
  387.             {
  388.                _loc2_ = _loc5_ - 1;
  389.             }
  390.          }
  391.       }
  392.       else if(depthFlag == mx.managers.DepthManager.kBottom)
  393.       {
  394.          for(_loc8_ in depthTable)
  395.          {
  396.             _loc9_ = depthTable[_loc8_];
  397.             _loc3_ = typeof _loc9_;
  398.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  399.             {
  400.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  401.                {
  402.                   _loc2_ = Math.min(_loc2_,_loc9_.getDepth());
  403.                }
  404.             }
  405.          }
  406.          _loc2_ -= 20;
  407.       }
  408.       else if(depthFlag == mx.managers.DepthManager.kTopmost)
  409.       {
  410.          for(_loc8_ in depthTable)
  411.          {
  412.             _loc9_ = depthTable[_loc8_];
  413.             _loc3_ = typeof _loc9_;
  414.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  415.             {
  416.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  417.                {
  418.                   _loc2_ = Math.max(_loc2_,_loc9_.getDepth());
  419.                }
  420.             }
  421.          }
  422.          _loc2_ += 100;
  423.       }
  424.       if(_loc2_ >= mx.managers.DepthManager.highestDepth)
  425.       {
  426.          _loc2_ = mx.managers.DepthManager.highestDepth;
  427.       }
  428.       var _loc6_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  429.       for(_loc9_ in depthTable)
  430.       {
  431.          var _loc4_ = depthTable[_loc9_];
  432.          if(_loc4_._parent != undefined)
  433.          {
  434.             _loc6_ = Math.min(_loc6_,_loc4_.getDepth());
  435.          }
  436.       }
  437.       if(_loc2_ <= _loc6_)
  438.       {
  439.          _loc2_ = _loc6_;
  440.       }
  441.       return _loc2_;
  442.    }
  443.    function buildDepthTable(Void)
  444.    {
  445.       var _loc5_ = new Array();
  446.       var _loc4_ = undefined;
  447.       for(_loc4_ in this)
  448.       {
  449.          var _loc2_ = this[_loc4_];
  450.          var _loc3_ = typeof _loc2_;
  451.          if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc2_.__getTextFormat != undefined)
  452.          {
  453.             if(_loc2_._parent == this)
  454.             {
  455.                _loc5_[_loc2_.getDepth()] = _loc2_;
  456.             }
  457.          }
  458.       }
  459.       return _loc5_;
  460.    }
  461. }
  462.