Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

position of clearInterval in a function?

Status
Not open for further replies.

styleBunny

Technical User
Jun 20, 2002
133
AU
hi gang,

i have this much script on the last frame of my timeline, where i want a movie sprite to do 5 random moves on the time line, then return to a specified postion

a = setInterval(pause, 40); //calls a function with .4 sec interval

//this function will do 5 random moves then set sprite to a fixed position.
function pause() {
for (y=0; y<5; y++) {
afnText._y = random(150);
afnText._x = random(150);
}
afntext._y = 200
afntext._x =150
}
clearInterval(a);
stop();


i cant work out where my clearInterval should go? it either doesnt work and the for loop keeps on going or it wont go at all.

Is what im trying to do possible? call a function from a frame script?
 
Putting the actions in a for loop as you have done means all of them execute on one frame so you'll never see the clip move. Also your interval is being called every .04 seconds at the moment.

Try this instead:

Code:
function pause() {
	afnText._y = random(150);
	afnText._x = random(150);
	count++;
	if (count>4) {
		clearInterval(a);
		afntext._y = 200;
		afntext._x = 150;
	}
}
_global.count = 0;
a = setInterval(pause, 400);







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top