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

  1. class mx.controls.MenuBar extends mx.core.UIComponent
  2. {
  3.    var __menus;
  4.    var __menuBarItems;
  5.    var __labels;
  6.    var boundingBox_mc;
  7.    var invUpdateDisplay;
  8.    var invUpdateSize;
  9.    var openMenuIndex;
  10.    var supposedToLoseFocus;
  11.    var background_mc;
  12.    var __menuDataProvider;
  13.    var labelFunction;
  14.    var __height;
  15.    var enableByPass;
  16.    var mask_mc;
  17.    var __width;
  18.    var isDown;
  19.    static var symbolName = "MenuBar";
  20.    static var symbolOwner = mx.controls.MenuBar;
  21.    static var version = "2.0.0.360";
  22.    var className = "MenuBar";
  23.    static var _s_MenuIndex = 0;
  24.    var topItemDepth = 200;
  25.    var menuBarBackLeftName = "MenuBarBackLeft";
  26.    var menuBarBackRightName = "MenuBarBackRight";
  27.    var menuBarBackMiddleName = "MenuBarBackMiddle";
  28.    var __backgroundWidth = 550;
  29.    var __marginWidth = 10;
  30.    var tabChildren = false;
  31.    var labelField = "label";
  32.    var clipParameters = {enabled:1,visible:1,labels:1,minWidth:1,minHeight:1};
  33.    function MenuBar()
  34.    {
  35.       super();
  36.    }
  37.    function init(Void)
  38.    {
  39.       super.init();
  40.       this.__menus = new Object();
  41.       this.__menuBarItems = new Array();
  42.       var _loc3_ = 0;
  43.       while(_loc3_ < this.__labels.length)
  44.       {
  45.          this.addMenu(this.__labels[_loc3_]);
  46.          _loc3_ = _loc3_ + 1;
  47.       }
  48.       this.boundingBox_mc._visible = false;
  49.       this.boundingBox_mc._width = this.boundingBox_mc._height = 0;
  50.    }
  51.    function draw(Void)
  52.    {
  53.       super.draw();
  54.       if(this.invUpdateDisplay)
  55.       {
  56.          this.updateDisplay(this.invUpdateSize);
  57.       }
  58.    }
  59.    function menuHide(event)
  60.    {
  61.       if(event.menu.menuBarIndex == this.openMenuIndex)
  62.       {
  63.          this.__menuBarItems[this.openMenuIndex].setLabelBorder("none");
  64.          delete this.openMenuIndex;
  65.       }
  66.    }
  67.    function onSetFocus()
  68.    {
  69.       super.onSetFocus();
  70.       this.getFocusManager().defaultPushButtonEnabled = false;
  71.    }
  72.    function onKillFocus()
  73.    {
  74.       super.onKillFocus();
  75.       this.getFocusManager().defaultPushButtonEnabled = true;
  76.       if(this.supposedToLoseFocus == undefined)
  77.       {
  78.          this.getMenuAt(this.openMenuIndex).hide();
  79.       }
  80.       delete this.supposedToLoseFocus;
  81.    }
  82.    function createChildren(Void)
  83.    {
  84.       super.createChildren();
  85.       if(this.background_mc == undefined)
  86.       {
  87.          this.createEmptyMovieClip("background_mc",0);
  88.          this.background_mc.createObject(this.menuBarBackLeftName,"bckLeft",1);
  89.          this.background_mc.createObject(this.menuBarBackRightName,"bckRight",2);
  90.          this.background_mc.createObject(this.menuBarBackMiddleName,"bckCenter",3);
  91.       }
  92.       if(!_global.isLivePreview)
  93.       {
  94.          var _loc4_ = this.createObject("BoundingBox","mask_mc",10);
  95.          this.setMask(_loc4_);
  96.       }
  97.       this.updateBackgroundDisplay();
  98.    }
  99.    function size(Void)
  100.    {
  101.       super.size();
  102.       this.updateDisplay(true);
  103.       this.updateBackgroundDisplay();
  104.    }
  105.    function addMenu(arg1, arg2)
  106.    {
  107.       var _loc2_ = this.__menuDataProvider.childNodes.length;
  108.       if(_loc2_ == undefined)
  109.       {
  110.          _loc2_ = 0;
  111.       }
  112.       return this.addMenuAt(_loc2_,arg1,arg2);
  113.    }
  114.    function addMenuAt(index, arg1, arg2)
  115.    {
  116.       if(this.__menuDataProvider == undefined)
  117.       {
  118.          this.__menuDataProvider = new XML();
  119.          this.__menuDataProvider.addEventListener("modelChanged",this);
  120.       }
  121.       var _loc8_ = undefined;
  122.       var _loc3_ = undefined;
  123.       var _loc4_ = arg1;
  124.       if(arg2 != undefined)
  125.       {
  126.          if(arg2 instanceof XML)
  127.          {
  128.             _loc3_ = this.__menuDataProvider.addMenuItemAt(index,arg1);
  129.             var _loc2_ = arg2.childNodes;
  130.             while(_loc2_.length != 0)
  131.             {
  132.                _loc3_.addMenuItem(_loc2_[0]);
  133.             }
  134.             _loc4_ = undefined;
  135.          }
  136.          else
  137.          {
  138.             arg2.attributes.label = arg1;
  139.             _loc4_ = arg2;
  140.          }
  141.       }
  142.       if(_loc4_ != undefined)
  143.       {
  144.          _loc3_ = this.__menuDataProvider.addMenuItemAt(index,_loc4_);
  145.       }
  146.       return this.insertMenuBarItem(index,_loc3_);
  147.    }
  148.    function insertMenuBarItem(index, mdp)
  149.    {
  150.       var _loc3_ = mx.controls.Menu.createMenu(_root,mdp,{styleName:this,menuBarIndex:index});
  151.       this.__menus[mdp.getID()] = _loc3_;
  152.       _loc3_.__menuBar = this;
  153.       _loc3_.addEventListener("menuHide",this);
  154.       _loc3_.border_mc.borderStyle = "menuBorder";
  155.       _loc3_.labelField = this.labelField;
  156.       _loc3_.labelFunction = this.labelFunction;
  157.       var _loc5_ = this.labelFunction(mdp);
  158.       if(_loc5_ == undefined)
  159.       {
  160.          _loc5_ = mdp.attributes[this.labelField];
  161.       }
  162.       var _loc4_ = this.createObject("MenuBarItem","mbItem" + this.topItemDepth++,this.topItemDepth,{owner:this,__initText:_loc5_,styleName:this,_visible:false});
  163.       _loc4_.setEnabled(this.enabled);
  164.       _loc4_.setSize(_loc4_.getPreferredWidth(),this.__height);
  165.       _loc3_.__activator = _loc4_;
  166.       this.__menuBarItems.splice(index,0,_loc4_);
  167.       this.invUpdateDisplay = true;
  168.       this.invalidate();
  169.       return _loc3_;
  170.    }
  171.    function getMenuAt(index)
  172.    {
  173.       return this.__menus[this.__menuDataProvider.childNodes[index].getID()];
  174.    }
  175.    function removeMenuAt(index)
  176.    {
  177.       var _loc2_ = this.__menuDataProvider.removeMenuItemAt(index);
  178.       var _loc3_ = this.__menuBarItems[index];
  179.       this.__menuBarItems.splice(index,1);
  180.       _loc3_.removeMovieClip();
  181.       var _loc5_ = this.__menus[_loc2_.getID()];
  182.       delete this.__menus[_loc2_.getID()];
  183.       this.invUpdateDisplay = true;
  184.       this.invalidate();
  185.       return _loc5_;
  186.    }
  187.    function setEnabled(b)
  188.    {
  189.       super.setEnabled(b);
  190.       var _loc4_ = this.__menuBarItems.length;
  191.       this.enableByPass = true;
  192.       var _loc3_ = 0;
  193.       while(_loc3_ < _loc4_)
  194.       {
  195.          this.__menuBarItems[_loc3_].setEnabled(b);
  196.          _loc3_ = _loc3_ + 1;
  197.       }
  198.       delete this.enableByPass;
  199.    }
  200.    function setMenuEnabledAt(index, enable)
  201.    {
  202.       if(!this.enabled && this.enableByPass == undefined)
  203.       {
  204.          return undefined;
  205.       }
  206.       this.__menuBarItems[index].setEnabled(enable);
  207.    }
  208.    function getMenuEnabledAt(index)
  209.    {
  210.       return this.__menuBarItems[index].enabled;
  211.    }
  212.    function setDataProvider(dp)
  213.    {
  214.       this.removeAll();
  215.       this.__menuDataProvider = dp;
  216.       dp.isTreeRoot = true;
  217.       var _loc3_ = dp.childNodes;
  218.       var _loc4_ = _loc3_.length;
  219.       var _loc2_ = 0;
  220.       while(_loc2_ < _loc4_)
  221.       {
  222.          this.insertMenuBarItem(_loc2_,_loc3_[_loc2_]);
  223.          _loc2_ = _loc2_ + 1;
  224.       }
  225.    }
  226.    function get dataProvider()
  227.    {
  228.       return this.__menuDataProvider;
  229.    }
  230.    function set dataProvider(dp)
  231.    {
  232.       this.setDataProvider(dp);
  233.    }
  234.    function get labels()
  235.    {
  236.       return this.__labels;
  237.    }
  238.    function set labels(lbls)
  239.    {
  240.       this.__labels = lbls;
  241.       var _loc4_ = this.__menuBarItems.length;
  242.       var _loc3_ = this.__labels.length;
  243.       var _loc2_ = 0;
  244.       while(_loc2_ < _loc4_)
  245.       {
  246.          this.removeMenuAt(0);
  247.          _loc2_ = _loc2_ + 1;
  248.       }
  249.       _loc2_ = 0;
  250.       while(_loc2_ < _loc3_)
  251.       {
  252.          this.addMenu(this.__labels[_loc2_]);
  253.          _loc2_ = _loc2_ + 1;
  254.       }
  255.       this.redraw(true);
  256.    }
  257.    function invalidateStyle(propName)
  258.    {
  259.       super.invalidateStyle(propName);
  260.       if(propName == "fontFamily" || propName == "fontSize" || propName == "fontWeight" || propName == "styleName")
  261.       {
  262.          this.invUpdateDisplay = true;
  263.          this.invUpdateSize = true;
  264.          this.invalidate();
  265.       }
  266.       var _loc3_ = 0;
  267.       while(_loc3_ < this.__menuBarItems.length)
  268.       {
  269.          this.getMenuAt(_loc3_).invalidateStyle(propName);
  270.          _loc3_ = _loc3_ + 1;
  271.       }
  272.    }
  273.    function changeColorStyleInChildren(sheet, styleProp, newValue)
  274.    {
  275.       super.changeColorStyleInChildren(sheet,styleProp,newValue);
  276.       var _loc3_ = 0;
  277.       while(_loc3_ < this.__menuBarItems.length)
  278.       {
  279.          this.getMenuAt(_loc3_).changeColorStyleInChildren(sheet,styleProp,newValue);
  280.          _loc3_ = _loc3_ + 1;
  281.       }
  282.    }
  283.    function notifyStyleChangeInChildren(sheet, styleProp, newValue)
  284.    {
  285.       super.notifyStyleChangeInChildren(sheet,styleProp,newValue);
  286.       var _loc3_ = 0;
  287.       while(_loc3_ < this.__menuBarItems.length)
  288.       {
  289.          this.getMenuAt(_loc3_).notifyStyleChangeInChildren(sheet,styleProp,newValue);
  290.          _loc3_ = _loc3_ + 1;
  291.       }
  292.    }
  293.    function updateDisplay(resize)
  294.    {
  295.       delete this.invUpdateDisplay;
  296.       delete this.invUpdateSize;
  297.       var _loc4_ = this.__marginWidth;
  298.       var _loc5_ = 0;
  299.       var _loc6_ = this.__menuBarItems.length;
  300.       var _loc3_ = 0;
  301.       while(_loc3_ < _loc6_)
  302.       {
  303.          var _loc2_ = this.__menuBarItems[_loc3_];
  304.          _loc2_._visible = true;
  305.          _loc2_.menuBarIndex = _loc3_;
  306.          this.getMenuAt(_loc3_).menuBarIndex = _loc3_;
  307.          if(resize)
  308.          {
  309.             _loc2_.setSize(_loc2_.getPreferredWidth(),this.__height);
  310.          }
  311.          var _loc0_ = null;
  312.          _loc4_ = _loc2_._x = _loc4_ + _loc5_;
  313.          _loc5_ = _loc2_.__width;
  314.          _loc3_ = _loc3_ + 1;
  315.       }
  316.    }
  317.    function updateBackgroundDisplay()
  318.    {
  319.       this.mask_mc._width = this.width;
  320.       this.mask_mc._height = this.height;
  321.       var _loc2_ = this.background_mc;
  322.       _loc2_._height = this.__height;
  323.       _loc2_.bckLeft._x = 0;
  324.       var _loc3_ = _loc2_.bckLeft._width;
  325.       _loc2_.bckCenter._width = this.__width - (_loc3_ + _loc2_.bckRight._width);
  326.       _loc2_.bckCenter._x = _loc3_;
  327.       _loc2_.bckRight._x = _loc3_ + _loc2_.bckCenter._width;
  328.    }
  329.    function showMenu(index)
  330.    {
  331.       this.openMenuIndex = index;
  332.       var _loc2_ = this.__menuBarItems[index];
  333.       var _loc3_ = {x:0,y:0};
  334.       _loc2_.setLabelBorder("falsedown");
  335.       _loc2_.localToGlobal(_loc3_);
  336.       var _loc4_ = this.getMenuAt(index);
  337.       _loc4_.focusManager.lastFocus = undefined;
  338.       _loc4_.show(_loc3_.x,_loc3_.y + (_loc2_._height + 1));
  339.    }
  340.    function removeMenuBarItemAt(index)
  341.    {
  342.       var _loc2_ = this.__menuBarItems[index];
  343.       var _loc3_ = _loc2_.__menu;
  344.       if(_loc2_ != undefined)
  345.       {
  346.          _loc3_.removeMovieClip();
  347.          _loc2_.removeMovieClip();
  348.          this.__menuBarItems.splice(index,1);
  349.          this.updateDisplay(false);
  350.       }
  351.    }
  352.    function removeAll()
  353.    {
  354.       while(this.__menuBarItems.length > 0)
  355.       {
  356.          var _loc2_ = this.__menuBarItems[0];
  357.          var _loc3_ = _loc2_.__menu;
  358.          _loc3_.removeMovieClip();
  359.          _loc2_.removeMovieClip();
  360.          this.__menuBarItems.splice(0,1);
  361.       }
  362.       this.updateDisplay(false);
  363.    }
  364.    function onItemRollOver(index)
  365.    {
  366.       var _loc3_ = this.__menuBarItems[index];
  367.       if(this.openMenuIndex != undefined)
  368.       {
  369.          var _loc2_ = this.openMenuIndex;
  370.          if(_loc2_ != index)
  371.          {
  372.             this.isDown = false;
  373.             var _loc4_ = this.__menuBarItems[_loc2_];
  374.             this.onItemRelease(_loc2_);
  375.             _loc4_.setLabelBorder("none");
  376.             this.showMenu(index);
  377.             this.isDown = true;
  378.          }
  379.       }
  380.       else
  381.       {
  382.          _loc3_.setLabelBorder("falserollover");
  383.          this.isDown = false;
  384.       }
  385.    }
  386.    function onItemPress(index)
  387.    {
  388.       var _loc2_ = this.__menuBarItems[index];
  389.       if(!this.isDown)
  390.       {
  391.          this.showMenu(index);
  392.          this.isDown = true;
  393.       }
  394.       else
  395.       {
  396.          _loc2_.setLabelBorder("falsedown");
  397.          this.isDown = false;
  398.       }
  399.       this.pressFocus();
  400.    }
  401.    function onItemRelease(index)
  402.    {
  403.       var _loc2_ = this.__menuBarItems[index];
  404.       if(!this.isDown)
  405.       {
  406.          this.getMenuAt(index).hide();
  407.          _loc2_.setLabelBorder("falserollover");
  408.       }
  409.       this.releaseFocus();
  410.    }
  411.    function onItemRollOut(index)
  412.    {
  413.       if(this.openMenuIndex != index)
  414.       {
  415.          this.__menuBarItems[index].setLabelBorder("none");
  416.       }
  417.    }
  418.    function onItemDragOver(index)
  419.    {
  420.       var _loc5_ = this.__menuBarItems[index];
  421.       if(this.openMenuIndex != undefined)
  422.       {
  423.          var _loc2_ = this.openMenuIndex;
  424.          if(_loc2_ != index)
  425.          {
  426.             this.isDown = false;
  427.             var _loc3_ = this.__menuBarItems[_loc2_];
  428.             this.onItemRelease(_loc2_);
  429.             _loc3_.setLabelBorder("none");
  430.          }
  431.       }
  432.       else
  433.       {
  434.          this.isDown = true;
  435.       }
  436.       this.onItemPress(index);
  437.    }
  438.    function onItemDragOut(index)
  439.    {
  440.       this.onItemRollOut(index);
  441.    }
  442.    function keyDown(e)
  443.    {
  444.       var _loc3_ = this.__menuBarItems.length;
  445.       var _loc8_ = undefined;
  446.       if(e.code == 39 || e.code == 37)
  447.       {
  448.          if(this.openMenuIndex == undefined)
  449.          {
  450.             this.openMenuIndex = -1;
  451.          }
  452.          var _loc2_ = this.openMenuIndex;
  453.          var _loc5_ = false;
  454.          var _loc4_ = 0;
  455.          while(!_loc5_ && _loc4_ < _loc3_)
  456.          {
  457.             _loc4_ = _loc4_ + 1;
  458.             _loc2_ = e.code != 39 ? _loc2_ - 1 : _loc2_ + 1;
  459.             if(_loc2_ >= _loc3_)
  460.             {
  461.                _loc2_ = 0;
  462.             }
  463.             else if(_loc2_ < 0)
  464.             {
  465.                _loc2_ = _loc3_ - 1;
  466.             }
  467.             if(this.__menuBarItems[_loc2_].enabled)
  468.             {
  469.                _loc5_ = true;
  470.             }
  471.          }
  472.          if(_loc4_ < _loc3_)
  473.          {
  474.             this.onItemRollOver(_loc2_);
  475.          }
  476.       }
  477.       if(Key.isDown(40))
  478.       {
  479.          if(this.openMenuIndex != undefined)
  480.          {
  481.             var _loc7_ = this.getMenuAt(this.openMenuIndex);
  482.             _loc7_.focusEnabled = true;
  483.             _loc7_.moveSelBy(1);
  484.             this.supposedToLoseFocus = true;
  485.             Selection.setFocus(_loc7_);
  486.          }
  487.       }
  488.       if(Key.isDown(13) || Key.isDown(27))
  489.       {
  490.          this.getMenuAt(this.openMenuIndex).hide();
  491.       }
  492.    }
  493. }
  494.