Web Analytics Made Easy -
StatCounter I can start the slideshow, but I can't make it stop - CodingForum

Announcement

Collapse
No announcement yet.

I can start the slideshow, but I can't make it stop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I can start the slideshow, but I can't make it stop

    Let me say in advance that this is all new to me, and I am sure that I am missing something obvious, but I'm stumped.

    I am working on adding start and stop functionality to the very excellent mooShow slideshow script. The 'autoPlay' function works fine, and 'startautoPlay' works by itself as well, but I cannot seem to make it stop once it has started. I've been fumbling around with this for all week, to no avail. I thought that using a variable and a while statement would do the trick, but adding the 'while' just crashes the browser (if the while is removed, and the 'startautoplay' is allowed to call 'autoplay' after the 'if...else' statement dealing with the timing of the slideshow, it works exactly as I expect it to).

    Code:
    	function autoPlay (delayTime,showName) { 
    		window.setInterval("mooShows[showName].nextImage()", delayTime);
    	}
    
    	function startautoPlay (newdelayTime) {
      		// Starts automatic slideshow via web link
    		// Defaults to 5 second delay if no delay time is set
    		var canPlay = 1;
      		if (newdelayTime > 0) {
        		this.delayTime = newdelayTime;
      			}
    		else {
    			this.delayTime = 5000;
      			}
    		while(canPlay = 1){  		
    			autoPlay(this.delayTime, showName);
    			}
    	}
    
    		function stopautoPlay () {
      		// Turns slide mode off
      		setcanPlay = 0;
    	}
    Any help or insight would be greatly appreciated.

  • #2
    Give this a try


    Assign this line to a variable

    window.setInterval("mooShows[showName].nextImage()", delayTime);

    such as

    timer=window.setInterval("mooShows[showName].nextImage()", delayTime);

    then use this function

    function stopMe(){
    clearInterval(timer)
    }
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

    Comment


    • #3
      thank you! that did indeed work. and I think I see the error in my thinking... all of my previous attempts to stop the slideshow revolved around clearing (or increasing to such a large number that it appeared to the end used to have cleared) the time between each slide, as opposed to stopping the function itself. It didn't occur to me to assign the whole function to a variable and then clear <i>it</i>.

      Out of curiosity, can anyone explain to me why did the 'while' function, as written above, crashed the web browser? I can see why it didn't work the way I wanted it to now, but I still don't see why it wouldn't run the function.

      Comment


      • #4
        From what I can see you are assigning canPLay a value instead of comparing it.

        while(canPlay = 1){ // assignment


        while(canPlay == 1){ // comparison

        and you have a variable called canPlay which has a value of 1 but in function stopautoPlay() your variable is called setcanPlay
        The silent one.

        The most dangerous thing in the world is an idea.
        The most dangerous person in the world is the one with an idea.

        Comment

        Working...
        X