How can I clear a timer when a variable is set to true?
<p>I'm just trying some JS animations, and I have animated a box that moves within borders, but I would like the animation to stop when the box hits one of the borders. This is one of the functions I use:</p>

<pre><code>function AnimMoveRight() {
    var interval = setInterval("moveRight(10)", 40);
    if (hitRight == true) {
        clearInterval(interval);
    }
}
</code></pre>

<p>The <code>moveRight(10)</code> changes the box'position for 10 pixels to the right. <code>hitRight</code> is set true when the box hits the right border. Well, obviously, this code doesn't work, it just keeps on looping the <code>moveRight()</code> function. Now, my question is, how do I cancel the interval from within the <code>AnimMoveRight()</code> function?</p>
