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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop a function from looping

Status
Not open for further replies.

wikfx

IS-IT--Management
Dec 16, 2001
196
0
0
MT
Hi all I have a function that loops, it keeps calling itself and I need it to stop on the press of a button can someone help me do this?? please? thanks

W i K
 
Make the function dependent on an outside variable (boolean). Something like:

Code:
_global.functionOK = true;
btn.onRelease = function() {
	_global.functionOK = false;
};
//start interval
var intervalID:Number = setInterval(myLoop, 10000);

function myLoop() {
	//check the _global variable and then proceed if true
	if (_global.functionOK) {
		//do this stuff
	} else {
		clearInterval(intervalID);
	}
}

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
cool thanks man

:)

W i K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top