1 Reply Latest reply on Aug 8, 2006 10:14 PM by Newsgroup_User

    Motion over time problem

    Angyl Level 1
      I'm trying to get a little triangle to move along the x axis to a location whenever you mouse over a button. Code is:

      var speed:Number = 10;
      function cbuttonOut()
      {
      if (navPointer._x>=500) {
      navPointer._x -= speed;
      }
      if (navPointer._x<=500) {
      navPointer._x += speed;
      }
      }

      May be a convoluted way to do it but it's not working as is. On each rollOver the nav pointer is inching a bit in the right direction instead of just sliding all the way on over.

      Maybe I'm misunderstanding the onRollOver event and it's a one-time thing instead of a constant??
        • 1. Re: Motion over time problem
          Level 7

          "Angyl" <webforumsuser@macromedia.com> wrote in message
          news:ebbnl8$5b0$1@forums.macromedia.com...
          > I'm trying to get a little triangle to move along the x axis to a location
          > whenever you mouse over a button. Code is:
          >
          > var speed:Number = 10;
          > function cbuttonOut()
          > {
          > if (navPointer._x>=500) {
          > navPointer._x -= speed;
          > }
          > if (navPointer._x<=500) {
          > navPointer._x += speed;
          > }
          > }
          >
          > May be a convoluted way to do it but it's not working as is. On each
          > rollOver
          > the nav pointer is inching a bit in the right direction instead of just
          > sliding
          > all the way on over.
          >
          > Maybe I'm misunderstanding the onRollOver event and it's a one-time thing
          > instead of a constant??
          >

          Yep, that is the problem. Events are fired once, and responded to once.

          The trick is to have the response do something repeatedly.

          One way to do this is with onEnterFrame. That event occurs as often as ( 1
          second / fps) where fps = "Frames Per Second" or "Frame Rate". So, if your
          fps = 2, then the onEnterFrame is fired once every 0.5 seconds.

          To use the onEnterFrame with an event response use as follows:

          buttonName.onRollOver = function() {
          var speed:Number = 20;
          this.onEnterFrame = function() {
          if (navPointer._x > 500) {
          navPointer._x -= speed;
          } else if (navPointer._x < 500) {
          navPointer._x += speed;
          } else {
          delete onEnterFrame;
          }
          }
          }

          Here, you are doing one thing for the onRollOver - defining an onEnterFrame
          that will run ever 1/fps seconds. Important Note*** the line delete
          onEnterFrame; deletes the function, thus making the onEnterFrame undefined.
          So, you could replace it with
          this.onEnterFrame = undefined;

          There are other ways to repeat a function and stop it when a criteria is
          met. (google "setInterval")

          You may also want to look at other ways to tween, such as will easing,
          bouncing, and more. (google "tween easing flash")

          HTH.