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