4 Replies Latest reply on Sep 29, 2011 8:01 AM by kglad

    Sliding images

    sam2986

      I have a header for a website that has three buttons on the left and when you click on each one it leads to another image that slides in from the right. I am trying to change some of the code in this because it is from someone that does not currently work here anymore and I am not by any means a flash person. I can do simple things so hopefully I will comprehend any answers I get.

       

      Here is what I want this header to do... Right now the only way it changes images is if you click on one of the buttons on the left, I want it to be able to also rotate automatically through them also. Say rotate to the next image every 10 seconds or so. I am pasting the code below  and any help I can get on this would be greatly appreciated.

       

      Thanks

       

      Here is the code from the action layer....

       

      var currentPosition:Number = contentHold.content1._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 = .3;

                              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;

                                          contentHold._x += dir*currentSpeed;

                                          if (Math.abs(distanceMoved-distanceToMove)<=1) {

                                                      contentHold._x = maskMovie._x-currentPosition+dir*distanceToMove;

                                                      currentPosition = input._x;

                                                      startFlag = false;

                                                      delete this.onEnterFrame;

                                          }

                              };

                  }

      };

      b1.onRelease = function() {

                  menuSlide(contentHold.content1);

      };

      b2.onRelease = function() {

                  menuSlide(contentHold.content2);

      };

      b3.onRelease = function() {

                  menuSlide(contentHold.content3);

      };

        • 1. Re: Sliding images
          Ron Colmen Level 2

          setInterval(yourFunction,10000); //1000=1sec

          1 person found this helpful
          • 2. Re: Sliding images
            sam2986 Level 1

            Rob, thanks for the quick response. So where would I want to insert this code? I am looking through it and I am not sure where I would want to insert it. Thanks again.

            • 3. Re: Sliding images
              sam2986 Level 1

              Also when you say (yourFunction) should I be inserting the movie clip that I want to rotate into these parenthasis? Thanks, so close to having this headache done and hopefully this is the last question.

              • 4. Re: Sliding images
                kglad Adobe Community Professional & MVP

                you can use:

                var menuSlideI:Number;

                var currentContent:Number = 1;

                var contentTotal:Number = 3;  // update this if you add more slides/buttons

                var currentPosition:Number = contentHold.content1._x;

                var startFlag:Boolean = false;

                menuSlide = function (input:MovieClip) {

                            if (startFlag == false) {

                                         clearInterval(menuSlideI);

                                        currentContent=input._name.split("content")[1];

                                        startFlag = true;

                                       

                                        var finalDestination:Number = input._x;

                                        var distanceMoved:Number = 0;

                                        var distanceToMove:Number = Math.abs(finalDestination-currentPosition);

                                        var finalSpeed:Number = .3;

                                        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;

                                                    contentHold._x += dir*currentSpeed;

                                                    if (Math.abs(distanceMoved-distanceToMove)<=1) {

                                                                contentHold._x = maskMovie._x-currentPosition+dir*distanceToMove;

                                                                currentPosition = input._x;

                                                                startFlag = false;

                                                                delete this.onEnterFrame;

                                                    }

                                        };

                            }

                };

                b1.onRelease = function() {

                            menuSlide(contentHold.content1);

                };

                b2.onRelease = function() {

                            menuSlide(contentHold.content2);

                };

                b3.onRelease = function() {

                            menuSlide(contentHold.content3);

                };

                 

                clearInterval(menuSlideI);

                menuSlideInterval=setInterval(menuSlide,10000,contentHold["content"+(1+currentContent%cont entTotal) ]);