4 Replies Latest reply on Jul 26, 2009 6:29 AM by Ned Murphy

    Switch 5 buttons control to simple 2 buttons (back-forth)

    adamlewen Level 1

      Hi there.

      I am having difficulties in manipulating a piece of code.

      The current piece will enable a user to click on one of 5 buttons and images will slide accordingly. (width slide)

      I would like to have only 2 buttons - BACK and FW... (a simple on (release) SLIDE to next or prev. image)

       

      Basically all I need is to be able to tell the FW BUTTON to slide +400 pixel on the X position

      and the BACK BUTTON to slide -400 pixels...

       

      Can anyone direct me? I know it has a very simple execution...

       

      Thanks!

       

      Here is the original code i am having trouble tewaking..

       

      stop();

      // _root.imagewidth defines the width of the image//
      _root.imagewidth = 400;

      // _root.speed defines the speed of the sliding images//
      _root.speed = 3;

      /* _root.trig.xposnew defines the x position of the
      sliding images */
      _root.trig.xposnew = -(_root.imagewidth);

      // Button 1
      but1.onRelease = function() {
          _root.trig.xposnew = -(_root.imagewidth);
      };

      //
      Button 2
      but2.onRelease = function() {
          _root.trig.xposnew = -((_root.imagewidth)*2);
      };

      //
      Button 3 and so on.....
      but3.onRelease = function() {
          _root.trig.xposnew = -((_root.imagewidth)*3);
      };

        • 1. Re: Switch 5 buttons control to simple 2 buttons (back-forth)
          Ned Murphy Adobe Community Professional & MVP

          What code do you have for actually moving anything?  The code you show only appears to be settings values, not changing anythings position or sliding.  The speed variable you have seems homeless, though my guess is it would be involved with some form of enterframe activity for the movement aspect of things.

           

          If that's all the code you have, you are missing some, but your explanation of what you want isn't clear enough for me to suggest anything at the moment.  This is further compounded by you saying you want tywo buttons and then showing code relative to three (and so on) buttons.

          • 2. Re: Switch 5 buttons control to simple 2 buttons (back-forth)
            adamlewen Level 1

            Hi Ned.

            There is a "trigger" MC in there holding this code:

             


            xpos = getProperty(_root.mainscroller.scroller, _x);

             

            xpos2 = xposnew-xpos;

             

            xmove = xpos2/_root.speed;

             

            setProperty(_root.mainscroller.scroller, _x, xpos+xmove);

             

             

            ---

             

            The piece of code i have attached earlier has nothing to do with what I am trying to achieve. It only "slides" the images in a way I would like to use when creating my FW/BACK Image slider situation.

             

            Basically all I am trying to create is a FW BUTTON that will slide +400 pixel on the X position

            and the BACK BUTTON to slide -400 pixels... (If using the images as a strip...).

            • 3. Re: Switch 5 buttons control to simple 2 buttons (back-forth)
              Ned Murphy Adobe Community Professional & MVP

              To slide what +/-400 pixels?  You make it sound like the buttons are being slid... one way for one and the opposite for the other.

               

              If you want to slide things in an animated manner, I suggest you explore the world of the coded Tween (class)... It's made for that sort of thing and should be explained in the help documentation... though I've never looked up the AS2 version of the helps files for them, only the AS3.

              1 person found this helpful
              • 4. Re: Switch 5 buttons control to simple 2 buttons (back-forth)
                Ned Murphy Adobe Community Professional & MVP

                Here's an example that should demo the Tween.  Create whatever object you want to have moved and give it an instance name of mcName (simply because that's the name I use in the code).  Then create you forward and back btns and give them instance names of fwdBtn and bckBtn... same reason for naming.

                 

                Then place the following code in the timeline that contains them...

                 

                import mx.transitions.Tween;
                import mx.transitions.easing.Regular;

                 

                var tw:Tween;
                var x0 = 0;
                var x400 = 400;

                 

                fwdBtn.onRelease = function(){

                tw = new Tween(mcName, "_x", Regular.easeIn, mcName._x, x400, 1, true);
                }

                 

                bckBtn.onRelease = function(){
                tw = new Tween(mcName, "_x", Regular.easeIn, mcName._x, x0, 1, true);
                }