2 Replies Latest reply on Aug 25, 2006 9:50 AM by Nickels55

    AS Stops working correctly

    Nickels55 Level 2
      I am helping someone edit a template that they purchased. The original file had 6 buttons, and when you move over a button the buttons below it shift downward. I figured out the code enough to add more buttons. Each button had to be named a number in sequencial order (ex: 1,2,3,4....). Everything worked great until I hit 10, then the array crapped out. The tenth button and so on didn't react like the other buttons, they didn't move down, and they didn't open correctly. Here is the code:


      link = new Array();
      frame = new Array();
      location = new Array();
      link[1] = "1.html";
      link[2] = "2.html";
      link[3] = "3.html";
      link[4] = "4.html";
      link[5] = "5.html";
      link[6] = "6.html";
      link[7] = "7.html";//link for button 7 (new 1)
      link[8] = "8.html";//link for button 8 (new 2)
      link[9] = "9.html";//link for button 9 (new 3)
      link[10] = "10.html";//link for button 10 (new 4)
      link[11] = "11.html";//link for button 10 (new 4)
      frame[1] = "_self";
      frame[2] = "_self";
      frame[3] = "_self";
      frame[4] = "_self";
      frame[5] = "_self";
      frame[6] = "_self";
      frame[7] = "_self";
      frame[8] = "_self";
      frame[9] = "_self";
      frame[10] = "_self";
      frame[11] = "_self";
      location = [80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80];
      numOfMenu = 11;
      gap = 35;
      speed = 6;
      _global.active = pageNum;
      _global.subActive = subNum;
      _global.over = active;
      for (i = 1; i <= numOfMenu + 1; i++)
      {
      this ._y = this.defaultY = (i - 1) * gap + this[1]._y;
      if (i > 1)
      {
      if (over)
      {
      if (this ._name <= over)
      {
      this
      .targetY = this .defaultY;
      }
      else
      {
      this
      .targetY = this .defaultY + location[over - 1];
      } // end else if
      }
      else
      {
      this
      .targetY = this .defaultY;
      } // end else if
      this
      ._y = this .targetY;
      } // end if
      this
      .bg.onRollOver = function ()
      {
      _global.over = this._parent._name;
      };
      this .bg.onRollOut = this.bg.onDragOut = function ()
      {
      _global.over = active;
      };
      this .bg.onRelease = function ()
      {
      getURL(link[this._parent._name], frame[this._parent._name]);
      };
      this
      .onEnterFrame = function ()
      {
      var _loc1 = this;
      if (over == _loc1._name)
      {
      _loc1.direction = "next";
      _loc1.nextFrame();
      return;
      } // end if
      _loc1.direction = "prev";
      _loc1.prevFrame();
      _loc1.prevFrame();
      };
      } // end of for
      this.onEnterFrame = function ()
      {
      var _loc1 = this;
      for (i = 2; i <= numOfMenu + 1; i++)
      {
      if (over)
      {
      if (_loc1 ._name <= over)
      {
      _loc1
      .targetY = _loc1 .defaultY;
      }
      else
      {
      _loc1
      .targetY = _loc1 .defaultY + location[over - 1];
      } // end else if
      continue;
      } // end if
      _loc1
      .targetY = _loc1 .defaultY;
      } // end of for
      for (i = 2; i <= numOfMenu + 1; i++)
      {
      _loc1
      ._y = _loc1 ._y + (_loc1.targetY - _loc1 ._y) / speed;
      } // end of for
      };
      this[numOfMenu + 1].onRollOver = function ()
      {
      };
      this[numOfMenu + 1].useHandCursor = false;


      Any idea why this works with 9 buttons but fails to work at 10 or more?
      Here is a sample of the buttons working (only 8 buttons)
      http://www.johnkalnin.com/test/~TARGET_GO_MENU_TEST.swf

      and not working:
      http://www.johnkalnin.com/test/11Buttons-test.swf

      Thanks for any help.
        • 1. Re: AS Stops working correctly
          Level 7
          Is this[1]._y a typo (index number 1) ?

          >> this ._y = this.defaultY = (i - 1) * gap + this[1]._y;


          • 2. AS Stops working correctly
            Nickels55 Level 2
            this._y = this.defaultY = (i - 1) * gap + this[1]._y;

            That could be a typo, what would you suggest changing it to?
            I am not an AS pro, I can read it enough to decypher it.

            I'll try:
            this._y = this.defaultY = (i - 1) * gap + this._y;
            and see if it works.

            UPDATE:
            this._y = this.defaultY = (i - 1) * gap + this._y; //Doesn't help fix problem
            and
            this._y = this.defaultY = (i - 1) * gap + this ._y; //doesn't work either - just makes gap btween buttons bigger

            Messing with that particular line of code does affect the layout. However, the buttons 10 and 11 are still don't move when the other buttons are moused-over.