Question : Using setInterval and clearInterval

I am trying to use setInterval and clearInterval to create a flashing dynamic text  box based on whether the value goes below 0. My code is attached, this code is inside a function that runs everytime the total is updated. When the total goes below 0 then the text starts to flash, however when the total is taken back above 0 the clearInterval doesn't seem to work the flashing continues. Help!!!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
if (totalRemaining < 0) { 		
		var negativeRemaining = setInterval(blink, 500);		
	} else {
		clearInterval(negativeRemaining);
	}
	blink = function() {
		_root.totalRemain._visible = _root.totalRemain._visible ? false : true; 
		updateAfterEvent();
	}
Open in New Window Select All

Answer : Using setInterval and clearInterval

on the first frame of your root make a variable

_global.negativeRemaining = 0;

your if statement:
1:
2:
3:
4:
5:
6:
7:
8:
if (totalRemaining < 0) {
    if(_global.negativeRemaining == 0) {
          _global.negativeRemaining = setInterval(blink, 500);  
    }
} else {
    clearInterval(_global.negativeRemaining);
    _global.negativeRemaining = 0;
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us