2 Replies Latest reply on May 7, 2006 6:01 PM by Newsgroup_User

    Loop variable not changing

    Level 7
      I've created a group of dynamic buttons and would like to add functionality
      to them. Below is my code that loops through a certain number of dynamic
      buttons adding a RollOver, RollOut and onRelease functions to them. I am
      having trouble with the last bit of code for the onRelease :
      _root.mov_albums.gotoAndStop("gal"+i);

      Basically, I want each button to link to a different point on the timeline
      flagged as "gal1", "gal2" etc. the problem is if say the "totalmain" is 8
      (than the last I value will be 8) it keeps setting the value to :
      _root.mov_albums.gotoAndStop("gal8");
      Instead of keeping making each one the appropriate value, am I missing
      something? thanks

      for(i=1;i<_root.totalmain;i++){
      _root["button"+i].onRollOver=function(){
      changecolor(this.fbuttxt, 0xFF000000);
      }
      _root["button"+i].onRollOut=function(){
      if (_root.currentbutton <> this){
      changecolor(this.fbuttxt, 0x999999);
      }
      }
      _root["button"+i].onRelease=function(){
      changecolor(_root.currentbutton.fbuttxt, 0x999999);
      _root.currentbutton = this;
      changecolor(this.fbuttxt, 0xFF000000);
      _root.mov_albums.gotoAndStop("gal"+i);
      }
      }

        • 1. Re: Loop variable not changing
          Level 7
          For _root.mov_albums.gotoAndStop("gal" + i); is using the value of i at the
          time the onRelease occurs which is after the loop is finished and so always
          8.

          Solution:
          for (i = 1; i < _root.totalmain; i++)
          {
          _root["button" + i].frameNumber = i;
          _root["button" + i].onRollOver = function()
          {
          changecolor(this.fbuttxt, 0xFF000000);
          };
          _root["button" + i].onRollOut = function()
          {
          if (_root.currentbutton <> this)
          {
          changecolor(this.fbuttxt, 0x999999);
          }
          };
          _root["button" + i].onRelease = function()
          {
          changecolor(_root.currentbutton.fbuttxt, 0x999999);
          _root.currentbutton = this;
          changecolor(this.fbuttxt, 0xFF000000);
          _root.mov_albums.gotoAndStop("gal" + this.frameNumber);
          };
          }
          --
          Lon Hosford
          www.lonhosford.com
          May many happy bits flow your way!
          "Timothy Robertson" <robertson@m-2-design.com> wrote in message
          news:C0838ED4.C675%robertson@m-2-design.com...
          I've created a group of dynamic buttons and would like to add functionality
          to them. Below is my code that loops through a certain number of dynamic
          buttons adding a RollOver, RollOut and onRelease functions to them. I am
          having trouble with the last bit of code for the onRelease :
          _root.mov_albums.gotoAndStop("gal"+i);

          Basically, I want each button to link to a different point on the timeline
          flagged as "gal1", "gal2" etc. the problem is if say the "totalmain" is 8
          (than the last I value will be 8) it keeps setting the value to :
          _root.mov_albums.gotoAndStop("gal8");
          Instead of keeping making each one the appropriate value, am I missing
          something? thanks

          for(i=1;i<_root.totalmain;i++){
          _root["button"+i].onRollOver=function(){
          changecolor(this.fbuttxt, 0xFF000000);
          }
          _root["button"+i].onRollOut=function(){
          if (_root.currentbutton <> this){
          changecolor(this.fbuttxt, 0x999999);
          }
          }
          _root["button"+i].onRelease=function(){
          changecolor(_root.currentbutton.fbuttxt, 0x999999);
          _root.currentbutton = this;
          changecolor(this.fbuttxt, 0xFF000000);
          _root.mov_albums.gotoAndStop("gal"+i);
          }
          }


          • 2. Re: Loop variable not changing
            Level 7
            Thanks for your reply, it works great!


            On 5/7/06 4:53 PM, in article e3lmpm$1m7$1@forums.macromedia.com, "Motion
            Maker" <macromedia@osfordusahay.com> wrote:

            > for (i = 1; i < _root.totalmain; i++)
            > {
            > _root["button" + i].frameNumber = i;
            > _root["button" + i].onRollOver = function()
            > {
            > changecolor(this.fbuttxt, 0xFF000000);
            > };
            > _root["button" + i].onRollOut = function()
            > {
            > if (_root.currentbutton <> this)
            > {
            > changecolor(this.fbuttxt, 0x999999);
            > }
            > };
            > _root["button" + i].onRelease = function()
            > {
            > changecolor(_root.currentbutton.fbuttxt, 0x999999);
            > _root.currentbutton = this;
            > changecolor(this.fbuttxt, 0xFF000000);
            > _root.mov_albums.gotoAndStop("gal" + this.frameNumber);
            > };
            > }