3 Replies Latest reply on Jun 25, 2013 12:54 PM by Ned Murphy

    Modifying variables to go up and down on certain frames

    Cool Colors

      I have declared these vars in the root:

      var nrpers:Number = 38;

      var zero:Number = 16;

       

      I need to modify these two vars  using two conditions:

      1. at each 12 frames and if i'm rollover on the play button (isplaying is true means i'm rollover the the play button)

      2. at each 12 frames and if i'm rollover on the rewind button (isrewinding is true means i'm rollover the the rewind button)

       

      Update here:

      the following code is inside a movieclip called "roata" that is in the _root.

       

      this.onEnterFrame = function()

      {

          if ((this._currentframe % 12 == 0) && (_root.isplaying == true))

          {

              if (_root.nrpers == 1)

              {

                  _root.nrpers = 38;

              }

              _root.nrpers = _root.nrpers - 1;

              if (_root.zero == 0)

              {

                  _root.zero = 16;

              }

              _root.zero = _root.zero - 1;

              trace(_root.zero);

              trace(_root.nrpers);

              _root.roata["orbiter" + _root.zero.toString()]["spinner"]["personaj"].gotoAndStop(_root.nrpers);

          }

       

      // the above code makes _root.zero to go like this 15-0, 15-0, ... in a  loop

      // also the above code makes _root.nrpers go from 37-1, 37-1, ...  in a loop

      // That is exactly what I want that code to do. It works great.

      // what I want is that the below code to go like this:

      // _root.zero to go from 0-15, 0-15, ... in a loop

      // _root.nrpers to go from 1-37, 1-37, ... in a loop

      // but it doesn't seem to work and I can't fix it even though I really tried, i'm missing smth, i'm in a "box"

      // the below code gives the following results:

      // _root.zero goes from 0-16, 0-16 ... in a loop   - so here I need 0-15, 0-15,... in a loop

      // _root.nrpers goes from 1-38, 1-38 ... in a loop - and here I need 1-37, 1-37, ... in a loop

       

          if ((this._currentframe % 12 == 0) && (_root.isrewinding == true))

          {

              if (_root.nrpers == 38)

              {

                  _root.nrpers = 0;

              }

              _root.nrpers = _root.nrpers + 1;

              if (_root.zero == 16)

              {

                  _root.zero = -1;

              }

              _root.zero = _root.zero + 1;

              trace(_root.zero);

              trace(_root.nrpers);

              _root.roata["orbiter" + _root.zero.toString()]["spinner"]["personaj"].gotoAndStop(_root.nrpers);

          }

      };

       

       

      Keep in mind when you make suggestions to modify the code that doesn't work or the root variables that it may affect the code that works. I need both code parts to works in conjunction modifying up and down those two variables. I tried to make this as clear as possible. Ask questions if something is unclear.

        • 1. Re: Modifying variables to go up and down on certain frames
          Ned Murphy Adobe Community Professional & MVP

          Try changing the test limit to be like the count up version where it tests the desired end value and not one less/more...

           

          if ((this._currentframe % 12 == 0) && (_root.isrewinding == true)) 

              {

                  if (_root.nrpers == 37)

                  {

                      _root.nrpers = 0;

                  }

                  _root.nrpers = _root.nrpers + 1;

                  if (_root.zero == 15)

                  {

                      _root.zero = -1;

                  }

                  _root.zero = _root.zero + 1;

                  trace(_root.zero);

                  trace(_root.nrpers);

                  _root.roata["orbiter" + _root.zero.toString()]["spinner"]["personaj"].gotoAndStop(_root.nrper s);

              }

          };

          • 2. Re: Modifying variables to go up and down on certain frames
            Cool Colors Level 1

            Using your code:

            I'm getting for _root.nrpers

            39

            40

            41

            42

            .

            .

            .

            and for _root.zero

            17

            18

            19

            20

            .

            .

            .

            Your code works if I modify the initial values of the variables like this

            _root.nrpers = 37;

            _root.zero = 15;

             

            But now my other code doesn't work as it should.

            _root.zero skips 15 the first time and shows:

            14-0, 15-0,15-0

            _root.nrpers skips 37 the first time and shows:

            36-1, 37-1, 37-1

            • 3. Re: Modifying variables to go up and down on certain frames
              Ned Murphy Adobe Community Professional & MVP

              Yes, either you need to use separate variables for forward versus backqard, or you need to adjust the initial value for each different case.