dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] restarting a setInterval

  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    63

    [F8] restarting a setInterval

    How do you re-start a setInterval?

    I've made a countdown script that uses setInterval. I've got a clear button that stops the clip, and I used clearInterval to do that. I need to know what script will allow me to re-start the countdown.

    countdown code
    function countDown () {
    seconds --;
    secondsText_txt.text = seconds;
    minutesText_txt.text = minutes;
    if (seconds <= 9) {
    secondsText_txt.text = "0" + seconds;
    }
    if (minutes <= 9) {
    minutesText_txt.text = "0" + minutes;
    }
    if (seconds <= 0) {
    minutes --;
    seconds = 59;
    }
    if (seconds == 0 && minutes == 0) {
    secondsText_txt._visible = false;
    minutesText_txt._visible = false;
    allClipsHidden ();
    countFinished_mc._visible = true;
    }
    if (minutes == 19 || minutes == 14 || minutes == 9 || minutes == 4) {
    allClipsHidden ();
    participants_mc._visible = true;
    } else if (minutes == 18 || minutes == 13|| minutes == 8||minutes == 3) {
    allClipsHidden ();
    chat_mc._visible = true;
    } else if (minutes == 17|| minutes == 12|| minutes == 7|| minutes == 2) {
    allClipsHidden ();
    whiteboard_mc._visible = true;
    } else if (minutes == 16 || minutes == 11|| minutes == 6|| minutes == 1) {
    allClipsHidden ();
    polling_mc._visible = true;
    }else if (minutes == 15) {
    allClipsHidden ();
    game1_mc._visible = true;
    } else if (minutes == 10) {
    allClipsHidden ();
    game2_mc._visible = true;
    } else if (minutes == 5) {
    allClipsHidden ();
    game3_mc._visible = true;
    } else if (minutes == 0) {
    game4_mc._visible = true;
    } else {
    allClipsHidden ();
    }
    }

    countInterval = setInterval (countDown, 1000);
    reset Script
    resetButton_btn.onRelease = function () {
    this.enabled = false;
    clearInterval (countInterval);
    timeColon_mc._visible = false;
    secondsText_txt._visible = false;
    minutesText_txt._visible = false;
    presentationStartText_mc._visible = false;
    manorCareLogo_mc._visible = false;
    peoplePictures_mc.gotoAndStop ("blank");
    labelText_mc._visible = true;
    allClipsHidden ();
    allPeopleHidden ();
    allBTSLogosHidden ();
    logoButtonsActive ();
    skinColorButtonsActive ();
    skinButtonsActive ();
    peopleButtonsActive ();
    minuteButtonsOn ();
    }
    button to restart script
    minute01_btn.onRelease = function () {
    minutesText_txt._visible = true;
    secondsText_txt._visible = true;
    timeColon_mc._visible = true;
    minutes = 0;
    seconds = 59;
    presentationStartText_mc._visible = true;
    manorCareLogo_mc._visible = true;
    logoButtonsHidden ();
    minuteButtonsOff ();
    peopleButtonsHidden ();
    skinButtonsHidden ();
    skinColorButtonsHidden ();
    labelText_mc._visible = false;
    resetButton_btn.enabled = true;
    }
    Last edited by Mordred58; 04-08-2008 at 02:34 PM.

  2. #2
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    tag your code
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  3. #3
    Member
    Join Date
    Jul 2005
    Posts
    63
    Let me try again...

    countdown script - with setInterval
    Code:
    function countDown () {
    	seconds --;
    	secondsText_txt.text = seconds;
    	minutesText_txt.text = minutes;
    	if (seconds <= 9) {
    		secondsText_txt.text = "0" + seconds;
    	}
    	if (minutes <= 9) {
    		minutesText_txt.text = "0" + minutes;
    	}
    	if (seconds <= 0) {
    		minutes --;
    		seconds = 59;
    	}
    	if (seconds == 0 && minutes == 0) {
    		secondsText_txt._visible = false;
    		minutesText_txt._visible = false;
    		allClipsHidden ();
    		countFinished_mc._visible = true;
    	}
    	if (minutes == 19 || minutes == 14 || minutes == 9 || minutes == 4) {
    		allClipsHidden ();
    		participants_mc._visible = true;
    	} else if (minutes == 18 || minutes == 13|| minutes == 8||minutes == 3) {
    		allClipsHidden ();
    		chat_mc._visible = true;
    	} else if (minutes == 17|| minutes == 12|| minutes == 7|| minutes == 2) {
    		allClipsHidden ();
    		whiteboard_mc._visible = true;
    	} else if (minutes == 16 || minutes == 11|| minutes == 6|| minutes == 1) {
    		allClipsHidden ();
    		polling_mc._visible = true;
    	}else if (minutes == 15) {
    		allClipsHidden ();
    		game1_mc._visible = true;
    	} else if (minutes == 10) {
    		allClipsHidden ();
    		game2_mc._visible = true;
    	} else if (minutes == 5) {
    		allClipsHidden ();
    		game3_mc._visible = true;
    	} else if (minutes == 0) {
    		game4_mc._visible = true;
    	} else {
    		allClipsHidden ();
    	}
    }
    
    countInterval = setInterval (countDown, 1000);
    Reset Button Code -- stops setInterval
    Code:
    resetButton_btn.onRelease = function () {
    	this.enabled = false;
    	clearInterval (countInterval);
    	timeColon_mc._visible = false;
    	secondsText_txt._visible = false;
    	minutesText_txt._visible = false;
    	presentationStartText_mc._visible = false;
    	manorCareLogo_mc._visible = false;
    	peoplePictures_mc.gotoAndStop ("blank");
    	labelText_mc._visible = true;
    	allClipsHidden ();
    	allPeopleHidden ();
    	allBTSLogosHidden ();
    	logoButtonsActive ();
    	skinColorButtonsActive ();
    	skinButtonsActive ();
    	peopleButtonsActive ();
    	minuteButtonsOn ();
    }
    button code -- to restart setInterval
    Code:
    minute05_btn.onRelease = function () {
    	minutesText_txt._visible = true;
    	secondsText_txt._visible = true;
    	timeColon_mc._visible = true;
    	minutes = 4;
    	seconds = 59;
    	manorCareLogo_mc._visible = true;
    	presentationStartText_mc._visible = true;
    	minuteButtonsOff ();
    	peopleButtonsHidden ();
    	logoButtonsHidden ();
    	skinButtonsHidden ();
    	skinColorButtonsHidden ();
    	labelText_mc._visible = false;
    	resetButton_btn.enabled = true;
    }

  4. #4
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    the same way that you used to start it originally
    countInterval = setInterval (countDown, 1000);

  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    63
    That worked. thanks!

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    pleasure

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center