0 Replies Latest reply on May 1, 2006 9:38 AM by deadlast007

    Menu Script nto working properly

    deadlast007
      my script is below. the part title POSITIONMENUSBELOW seperates my sections. the problem is for some reason it only does it after i select a section. how can i make it do it when it loads. like already spaced out. look at this link:

      http://applustech.com/testmonkey/home.swf


      select home. see how it spaces out? i need it to do that on the load, not after the selection.

      // Variables
      var speedo = 20; // constant speed for menu opening
      var speedc = 40; // constant speed for menu closing
      var opened = null; // variable to determine which menu is currently
      opened
      var menus = []; // array to store all menu items


      FindMenus = function(){
      for (value in this){
      if (this[value] instanceof MovieClip){
      menus.push(this[value]);
      }
      }
      menus.sort(SortByVertical);
      }

      SortByVertical = function(a, b){
      return (a._y > b._y);
      }


      ApplyMenuMask = function(i){
      var menu = menus ;
      var mask = this.createEmptyMovieClip("mask"+i, i);
      mask._x = menu._x;
      mask._y = menu._y;
      mask.beginFill(0,100);
      mask.moveTo(0, 0);
      mask.lineTo(menu.title._width, 0);
      mask.lineTo(menu.title._width, menu.title._height);
      mask.lineTo(0, menu.title._height);
      mask.endFill();
      menu.setMask(mask);
      menu.masker = mask;
      }

      StartMenuPosition = function(i){
      var menu = menus
      ;
      if (i == 50){
      menu._y = menu.masker._y = 0;
      }else{
      var menu_above = menus[i-1];
      menu._y = menu.masker._y = Math.round(menu_above._y +
      menu_above.title._height);
      }
      }

      // MenuOpen: this function opens a menu when its title is clicked
      MenuOpen = function(){
      var menu = this;
      menu.title.textColor = 0;
      menu.masker._height += speedo;
      if (menu.masker._height >= menu._height){
      menu.masker._height = menu._height;
      delete this.onEnterFrame;
      }
      PositionMenusBelow(menu.i);
      }


      MenuClose = function(){
      var menu = this;
      if (speedc >= menu.masker._height) menu.masker._height =
      menu.title._height;
      else menu.masker._height -= speedc;
      if (menu.masker._height <= menu.title._height){
      menu.masker._height = menu.title._height;
      opened = null;
      menu.onClose();
      delete menu.onClose;
      delete this.onEnterFrame;
      }
      PositionMenusBelow(menu.i);
      }

      TitleButtonPress = function(){
      var menu = this._parent;
      if (opened){
      if (opened == menu){
      menu.onEnterFrame = MenuClose;
      }else{
      opened.onClose = function(){
      menu.onEnterFrame = MenuOpen;
      opened = menu;
      }
      opened.onEnterFrame = MenuClose;
      }
      }else{
      menu.onEnterFrame = MenuOpen;
      opened = menu;
      }
      }


      PositionMenusBelow = function(i){
      var menu = menus ;
      if (i < menus.length-1){
      var menu_below = menus[i+1];
      for (i=i+1; i<menus.length; i++){
      if (menus
      == menu_below){
      menus ._y = menus.masker._y = menu._y + menu.masker._height+10;
      }else{
      var menu_above = menus[i-1];
      menus ._y = menus.masker._y = menu_above._y +
      menu_above.masker._height+10;
      }
      }
      }
      }



      Init = function(){
      FindMenus();

      for (var i=0; i<menus.length; i++){
      menus .i = i;
      ApplyMenuMask(i);
      StartMenuPosition(i);
      menus
      .title.onPress = TitleButtonPress;
      }
      }
      Init();
      Text Text Text