1 Reply Latest reply on Jul 23, 2006 7:52 AM by jonnybennett

    stopping an animation

    jonnybennett Level 1
      Here is a function that I have on a setInterval. I want it to animate a m.c. called anim... until that m.c. has a (height-20)=_global.globalHeight..... and.... a (width-20)=_global.globalWidth... When it is equal, I want to clear the set Interval.
      However because I am incrementing by+=10, there isn't a time when they are equal... therefore I can't stop the setInterval, and the dimensions of the m.c. are not exactly how I want them.

      Is there a way in the if statement to make it more like a for statement and say that when or if it goes over a limit then it must take on that value...


      function animMove() {
      if (anim._width-20<_global.globalWidth){
      anim._width+=10;
      updateAfterEvent();}
      if (anim._width-20>_global.globalWidth){
      anim._width-=10;
      updateAfterEvent();}
      if (anim._height-20<_global.globalHeight){
      anim._height+=10;
      updateAfterEvent();}
      if (anim._height-20>_global.globalHeight){
      anim._height-=10;
      updateAfterEvent();}
      if (anim._height-20==_global.globalHeight&&anim._width-20==_global.globalWidth){
      clearInterval(myInterval);}}

      myInterval=setInterval(animMove,1)

      Anyway if you understand and can help please do. Thanks alot Jonny.
        • 1. Re: stopping an animation
          jonnybennett Level 1
          Having just osted I have got the answer, however it is pretty dirty for want of a better word, so if anyone knows of a better way of scripting the whole thinig then please share... Thanks J...


          function animMove() {
          if (anim._width-20<_global.globalWidth){
          anim._width+=10;
          updateAfterEvent();}
          if (anim._width-20>_global.globalWidth){
          anim._width-=10;
          updateAfterEvent();}
          if (anim._height-20<_global.globalHeight){
          anim._height+=10;
          updateAfterEvent();}
          if (anim._height-20>_global.globalHeight){
          anim._height-=10;
          updateAfterEvent();}
          diffWidth=(anim._width-20)-_global.globalWidth;
          diffHeight=(anim._height-20)-_global.globalHeight;
          if (diffWidth<=1&&diffHeight<=1){
          anim._height=_global.globalHeight+20;
          anim._width=_global.globalWidth+20;}
          if (anim._height-20==_global.globalHeight&&anim._width-20==_global.globalWidth){
          clearInterval(myInterval);}}