Setinterval doesn't loop back
I want to make a clip expand/shrink upon rolling over/out of a button. Also I want to control its expanding/shrinking speed, so I'm using setinterval for this. This code kinda works, but only while expanding to yscale 300. When I rollout it should shrink back to 0 again, but it looks like it jumps back and forth from 290 to 300. What am I doing wrong?
Code:
var i:Number = 0;
function Increase() {
if (i<=200) {
clip._yscale = i;
i = i+20;
} else {
clearInterval(nInterval);
}
}
function Decrease() {
if (i>0) {
clip._yscale = i;
i = i-20;
} else {
clearInterval(nInterval);
}
}
//
button.onRollOver = function() {
var nInterval:Number = setInterval(Increase, 20);
};
button.onRollOut = function() {
var nInterval:Number = setInterval(Decrease, 20);
};