954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Stop one function with another OR call function()->Function()

Question it title, how to do it ?

I need to stop a function with another function or I need to call a global function inner function with another global function so I could stop it that way. I know its possible but how ?

Martin C++
Light Poster
43 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Could you maybe write the sudo code for what you are talking about?

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 
function change(){
//changes slides in my div
}

function stop_change(){ //Pause would be even better
//Should stop the change() function and make the slideshow pause
}


This is my actual code at the moment:

function change(){

	/*Change these values according to your needs*/

	if(typeof(step) == "undefined"){
		newElem = document.createElement('img');
		linkPause = document.createElement('a');
		namePause = document.createTextNode("Pause");
		linkPause.appendChild(namePause);
		linkPause.setAttribute("onclick", "pause()");
		linkPause.style.position = "absolute";
		
		slideDiv = document.getElementById('slideshow'); //Name of the division that the slideshow will occur on
		slideDiv.appendChild(newElem);
		slideDiv.appendChild(linkPause);

		extention = "jpg";
		imgPath = "images/"
		numImg = 2; //How many images you want to add in slideshow. Slides start from 1 and are limited with this variable
	}

	((typeof(step) != "undefined" && step<=numImg) ? step = step : step = 1);
	newElem.src = imgPath + step + "." + extention;
	step++;
	setTimeout("change()", 2000);
}

function pause(){

}
Martin C++
Light Poster
43 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 
var timer = null;

function change(){
 
	/*Change these values according to your needs*/
 
	if(typeof(step) == "undefined"){
		newElem = document.createElement('img');
		linkPause = document.createElement('a');
		namePause = document.createTextNode("Pause");
		linkPause.appendChild(namePause);
		linkPause.setAttribute("onclick", "pause()");
		linkPause.style.position = "absolute";
 
		slideDiv = document.getElementById('slideshow'); //Name of the division that the slideshow will occur on
		slideDiv.appendChild(newElem);
		slideDiv.appendChild(linkPause);
 
		extention = "jpg";
		imgPath = "images/"
		numImg = 2; //How many images you want to add in slideshow. Slides start from 1 and are limited with this variable
	}
 
	((typeof(step) != "undefined" && step<=numImg) ? step = step : step = 1);
	newElem.src = imgPath + step + "." + extention;
	step++;
	timer = setTimeout("change()", 2000);
}
 
function pause(){
   clearTimout(timer);
}


Basically create a variable that is going to hold the numeric value for your timer. Then when you pause, clearout the timer, essentially pausing it. If you need it to start again, call the change function.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

Thanks, it worked perfectly ! I just have one more question. Is there any way to resume the change() func from where it left off. I mean so it would resume with same picture it was paused with. Should I create a variable to hold the variable step data and then reuse it or is there any better way to do it ?

Martin C++
Light Poster
43 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 
Should I create a variable to hold the variable step data and then reuse it

Sounds about right to me.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You