3 Replies Latest reply on Sep 21, 2008 2:49 PM by kglad

    Infinitely Scrolling Menu

    Mister Peanut Level 1
      I am trying to start the menu from any given random location using the following code:

      onClipEvent (load){
      _x=Math.round(Math.random()*1992);
      }

      It doesn't seem to work. Can anyone tell me what might be going wrong? 1992 is the length of my movie clip, So I want it to choose any random spot on this movie clip to start from.

      Also, I am trying to only have this menu scroll when the mouse is over the movie clip. I'm trying to use an if statement to state that if the mouse is between _x 0 and _x 600 (this is the width of my clip) and between _y 0 and _y 150, then activate the scrolling function. This is the code I made, which I know is really wrong:

      onClipEvent (enterFrame)
      {
      if (_xmouse=(_x>0 & _x<600)){
      var distance=_root._xmouse-xcenter;
      _x+=(distance*speed);
      }
      }

      The code is on the movie clip, as you can see, but I'm really bad with syntax and grammar....

      Cheers for any help.

      P
        • 1. Re: Infinitely Scrolling Menu
          Mister Peanut Level 1
          I think I have almost figured it our. I got the Math.random working how I want it, and I placed all my code on an actions frame, but now I've lost smooth scrolling. Here is my code:

          var xcenter=300;
          var speed=1/5;

          var distance=_xmouse-xcenter;
          menu_general._x+=(distance*speed);


          menu_general.onRollOver = function()
          {
          var distance=_xmouse-xcenter;
          menu_general._x+=(distance*speed);
          if (menu_general._x > 75) menu_general._x=-1992.8;
          if (menu_general._x < -2067.8) menu_general._x=0;
          }

          menu_general.onRollOver = function(){
          menu_general._x=Math.round(Math.random()*-1992);
          }

          Please, please somebody assist me on this....

          P
          • 2. Re: Infinitely Scrolling Menu
            Mister Peanut Level 1
            Well, as this was a time-sensitive project, I've had to find another solution:

            I just made 2 frames for the menu. When you roll over the menu, it goes to frame 2 and plays the scrolling menu with my original code that was placed on the movie clip. I can't figure out what's wrong with what I was originally trying to do, but this is an okay plan 'B'

            Still, if anyone can help me with my original problem above, I'd really appreciate it.

            P
            • 3. Re: Infinitely Scrolling Menu
              kglad Adobe Community Professional & MVP
              you must use a loop of some kind (like onEnterFrame or setInterval) to animate anything. so, you could start a loop in your onRollOver handler, for example.

              and you can have, at most, one onRollOver handler per object.