A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Add a stop start to a timer

  1. #1
    Ctrl Z Ctrl Z F1 Ctrl Z Ctrl Z PONYACK's Avatar
    Join Date
    Nov 2005
    Location
    North Carolina
    Posts
    202

    [F8] Add a stop start to a timer

    Hi,

    I am using this great code made by Kenneth Andersson.

    I have been trying to add a stop start button.

    Any ideas would be great.

    Thanks


    Code:
    //First we need a dynamic textfield with instance name "theText", check.
    //Then we set the total number of minutes. I picked 64 to reduce the
    //result-view-waiting-time. 119 would just be... boring.
    total = 45;
    //Calculate the var total and update the textfield.
    this.onEnterFrame = function() {
    	minutes = Math.floor(total/60);
    	seconds = total%60;
    	theText.text = "0"+minutes+":"+seconds;
    	if (seconds<=9) {
    		theText.text = "0"+minutes+":"+"0"+seconds;
    	}
    };
    //Function for the countdown, can be changed to total++ if you want to
    //count "into the future" or something. Well I dunno.
    //clearInterval = When minutes and seconds is 00:00 it stops.
    counter = function () {
    	total--;
    	if (minutes == 0 & seconds == 1) {
    		clearInterval(setIt);
    	}
    	if (total == 30) {
    			warning.text="Warning, times almost up!";
    			gotoAndPlay(_currentframe+1);
    					}
    		if (total == 00) {
    			gotoAndPlay(_currentframe+1)
    		}
    };
    //Then we start an interval with the counter function, 1000 is milliseconds á 1 sec.
    setIt = setInterval(this, "counter", 1000);
    stop();

  2. #2
    Junior Member
    Join Date
    Aug 2007
    Posts
    1
    Quickly looking at the code just make the start button clear the interval and make the stop button set it again.
    David Federman
    Network Logistic, Inc.
    Developer
    http://networklogistic.com

  3. #3
    Ctrl Z Ctrl Z F1 Ctrl Z Ctrl Z PONYACK's Avatar
    Join Date
    Nov 2005
    Location
    North Carolina
    Posts
    202

    Adding Buttons

    Thanks for the reply.

    I changed this line to read.

    Code:
    setIt = setInterval(counter,  1000);
    Once i did that and updated my start button to refelect the change, the timer start stop worked.



    This is what I have been working on. The stop button works. But I can't get the start button to work...




    Code:
    stop_btn.onRelease = function() {
    	clearInterval(setIt);
    }
    
    start_btn.onRelease = function() {
    	setIt = setInterval(this,"counter", 1000);
    	
    }
    Last edited by PONYACK; 08-01-2007 at 04:37 PM. Reason: I think I got it

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