1 Reply Latest reply on Jun 24, 2007 3:29 PM by Iron_Mike

    Noob needs help with this code...

    Iron_Mike Level 1
      Hi,

      I found this code in a nice tutorial and I wanna make slight adjustments to the code.

      Unfortunately my Action Script skills are very limited... ;)

      This is the code for a 'sliding menue', depending on which button u pressed it will 'slide' to the appropriate picture.

      Here's the code:


      var currentPosition:Number = large_pics.pic1._x;
      var startFlag:Boolean = false;
      menuSlide = function (input:MovieClip) {

      if (startFlag == false) {


      startFlag = true;

      var finalDestination:Number = input._x;
      var distanceMoved:Number = 0;
      var distanceToMove:Number = Math.abs(finalDestination-currentPosition);
      var finalSpeed:Number = .2;
      var currentSpeed:Number = 0;
      var dir:Number = 1;

      if (currentPosition<=finalDestination) {

      dir = -1;

      } else if (currentPosition>finalDestination) {

      dir = 1;

      }

      this.onEnterFrame = function() {

      currentSpeed = Math.round((distanceToMove-distanceMoved+1)*finalSpeed);
      distanceMoved += currentSpeed;
      large_pics._x += dir*currentSpeed;
      if (Math.abs(distanceMoved-distanceToMove)<=1) {

      large_pics._x = mask_pics._x-currentPosition+dir*distanceToMove;
      currentPosition = input._x;
      startFlag = false;
      delete this.onEnterFrame;

      }

      };

      }

      };
      b1.onRelease = function() {

      menuSlide(large_pics.pic1);

      };
      b2.onRelease = function() {

      menuSlide(large_pics.pic2);

      };
      b3.onRelease = function() {

      menuSlide(large_pics.pic3);

      };
      b4.onRelease = function() {

      menuSlide(large_pics.pic4);

      };

      I need to adjust five things in this code...

      (1) I want this menue to slide vertically not horizontally.

      I changed the 'x' values in the code to 'y' which I thought would make it move vertically, but it doesn't work...

      (2) Is it possible that, whatever the distance is, the "sliding" time is always 2.2 sec ?

      (3) I need to implement code that after the final position is reached, the timeline jumps to a certain movieclip to a certain label - depending on what button was pressed of course...

      I tried to implement this code for button number two...

      b2.onRelease = function() {

      menuSlide(large_pics.pic2);

      }

      if (currentPosition = finalDestination) {

      this.large_pics.pic2.gotoAndPlay("s1");

      };

      --> sliding still works but it doesn't jump to the appropriate label...

      (4) I wanna add 'Next' & 'Previous' buttons to the slide show - what would be the code in this case scenario ?

      My first thought was something like that Flash checks which 'pic' movieclip it is showing right now (pic1, pic2, pic3 etc.) and depending on what button u pressed u go to the y value of movieclip 'picX + 1' (Next button) or 'picX - 1' (Previous button)...

      Is that possible ?

      (5) After implementing the Next & Previous buttons I need to make sure that when it reached the last pic movieclip it will not go further on the y value - because there is no more pic movieclip.

      Options are to either slide back to movieclip 'pic1' or simply do nothing any more on the next button...

      I know this is probably Kindergarten for you, but I have only slight ideas how to do this and no code knowledge to back it up... haha

      Thanx a lot for your help in advance !

      Always a pleasure to learn from u guys... ;)

      Mike
        • 1. Noob needs help with this code...
          Iron_Mike Level 1
          Hi,

          I made some progress with the code thanx to the help of Simon, but there are still 2 things that need to be addressed...

          (1) I want the sliding time always to be 2.2 sec...

          here's my approach to it - just a theory but it might work:

          we need a speed that changes dynamically depending on the distance we have to travel...

          I don't know if that applies for Action Scrip but I recall from 6th grade, that...

          speed = distance / time

          --> we got the time (which is always 2.2 sec)
          --> we got the disctance (currentposition-finaldestination)

          --> this should automatically change the speed to the appropriate value

          Unfortunately I have no clue how the action script would look like (like I said my action script skills are very limited)...

          (2) Also, one other thing I need that is not implemented yet, is that when the final destination is reached it jumps to a certain label inside a certain movieclip - every time different for each button pressed - something like:

          if (currentPosition = finalDestination) {

          this.large_pics.pic2.gotoAndPlay("s1");

          };

          that statement just doesn't work when I put it right under the function for each button...

          Thanx again for taking the time !!!

          Mike