Question : having trouble with setInterval();

good day,

the code attached is for a photo gallery.  the problem i am having is with the setInterval().  when you initially roll over a button the first time and the roll out the code works.  but when you roll over and out a  second time the timing of all the intervals seem to start again overlapping each other.  is there anything you see that would cause this?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
stop();
import mx.transitions.Tween;
 
var currentThumb = 1;
 
_root.image2._alpha = 0;
_root.image3._alpha = 0;
_root.image4._alpha = 0;
_root.image5._alpha = 0;
 
function updateTimer():Void {
 
	if(currentThumb < 5){
		
		oldThumb = currentThumb;
		currentThumb++;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);
	
	}
 
	else if(currentThumb == 5){
 
		oldThumb = currentThumb;
		currentThumb = 1;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);		
 
	}
 
}
 
var intervalID:Number = setInterval(updateTimer, 5000);
 
	//-----
	_root.thumbs.thumbbt1.onRollOver = function(){
 
		clearInterval(intervalID);
		oldThumb = currentThumb;
		currentThumb = 1;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);		
		
	}
	_root.thumbs.thumbbt1.onRollOut = function(){
		var intervalID:Number = setInterval(updateTimer, 5000);
	}
	//-----
	//-----	
	_root.thumbs.thumbbt2.onRollOver = function(){
 
		clearInterval(intervalID);
		oldThumb = currentThumb;
		currentThumb = 2;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);		
		
	}
	_root.thumbs.thumbbt2.onRollOut = function(){
		var intervalID:Number = setInterval(updateTimer, 5000);
	}	
	//-----
	_root.thumbs.thumbbt3.onRollOver = function(){
 
		clearInterval(intervalID);
		oldThumb = currentThumb;
		currentThumb = 3;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);		
		
	}
	_root.thumbs.thumbbt3.onRollOut = function(){
		var intervalID:Number = setInterval(updateTimer, 5000);
	}	
	//-----	
	_root.thumbs.thumbbt4.onRollOver = function(){
 
		clearInterval(intervalID);
		oldThumb = currentThumb;
		currentThumb = 4;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);		
		
	}
	_root.thumbs.thumbbt4.onRollOut = function(){
		var intervalID:Number = setInterval(updateTimer, 5000);
	}	
	//-----	
	_root.thumbs.thumbbt5.onRollOver = function(){
 
		clearInterval(intervalID);
		oldThumb = currentThumb;
		currentThumb = 5;
 
		var thumbTween1:Tween = new Tween(_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb"+oldThumb]._x, _root["thumbs"]["thumb"+currentThumb]._x, 1, true);
		var imageTween1:Tween = new Tween(_root["image"+oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
		var imageTween2:Tween = new Tween(_root["image"+currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);		
		
	}
	_root.thumbs.thumbbt5.onRollOut = function(){
		var intervalID:Number = setInterval(updateTimer, 5000);
	}
Open in New Window Select All

Answer : having trouble with setInterval();

Hey,

Solution is here you have "intervalID" declared at several times i have removed the declaration all the places and just kept it in the global part alone....


/// Edited code is here...

Jon
/////////////////////////////////////////
stop ();
import mx.transitions.Tween;

var currentThumb = 1;

_root.image2._alpha = 0;
_root.image3._alpha = 0;
_root.image4._alpha = 0;
_root.image5._alpha = 0;

function updateTimer ():Void
{

      if (currentThumb < 5)
      {

            oldThumb = currentThumb;
            currentThumb++;

            var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
            var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
            var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

      }
      else if (currentThumb == 5)
      {

            oldThumb = currentThumb;
            currentThumb = 1;

            var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
            var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
            var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

      }
}
var intervalID:Number = setInterval (updateTimer, 5000);

//-----
_root.thumbs.thumbbt1.onRollOver = function ()
{

      clearInterval (intervalID);
      oldThumb = currentThumb;
      currentThumb = 1;

      var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
      var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
      var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

};
_root.thumbs.thumbbt1.onRollOut = function ()
{
      clearInterval (intervalID);
      intervalID = setInterval (updateTimer, 5000);
};
//-----
//-----
_root.thumbs.thumbbt2.onRollOver = function ()
{

      clearInterval (intervalID);
      oldThumb = currentThumb;
      currentThumb = 2;

      var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
      var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
      var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

};
_root.thumbs.thumbbt2.onRollOut = function ()
{
      clearInterval (intervalID);
      intervalID= setInterval (updateTimer, 5000);
};
//-----
_root.thumbs.thumbbt3.onRollOver = function ()
{

      clearInterval (intervalID);
      oldThumb = currentThumb;
      currentThumb = 3;

      var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
      var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
      var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

};
_root.thumbs.thumbbt3.onRollOut = function ()
{
      clearInterval (intervalID);
      intervalID = setInterval (updateTimer, 5000);
};
//-----
_root.thumbs.thumbbt4.onRollOver = function ()
{

      clearInterval (intervalID);
      oldThumb = currentThumb;
      currentThumb = 4;

      var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
      var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
      var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

};
_root.thumbs.thumbbt4.onRollOut = function ()
{
      clearInterval (intervalID);
      intervalID = setInterval (updateTimer, 5000);
};
//-----
_root.thumbs.thumbbt5.onRollOver = function ()
{

      clearInterval (intervalID);
      oldThumb = currentThumb;
      currentThumb = 5;

      var thumbTween1:Tween = new Tween (_root.thumbs.thumbmask, "_x", mx.transitions.easing.Strong.easeOut, _root["thumbs"]["thumb" + oldThumb]._x, _root["thumbs"]["thumb" + currentThumb]._x, 1, true);
      var imageTween1:Tween = new Tween (_root["image" + oldThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, 1, true);
      var imageTween2:Tween = new Tween (_root["image" + currentThumb], "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);

};
_root.thumbs.thumbbt5.onRollOut = function ()
{
      clearInterval (intervalID);
      intervalID = setInterval (updateTimer, 5000);
};
Random Solutions  
 
programming4us programming4us