A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    83

    Timer reset in AS 2.0

    Hi

    Is it possible to reset a timer in AS 2.0? If, yes...how?

    /S

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    a few more details would be good
    here is a simple example
    the output window will update every second with the value of variable i
    if i>10 the interval is cleared
    Code:
    var i:Number = 0;
    traceInterval = setInterval(tracer,1000);
    
    function tracer(){
    i>10 ? clearInterval(traceInterval) : trace(i++);
    };
    hth ??

  3. #3
    Member
    Join Date
    Jun 2004
    Posts
    83
    Thanks, but I was more after a reset function connected to the getTimer() function. Think the timer class is quite well developed in AS 3.0.

    /S-fish

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    can you make use of this method using
    2 buttons and a textfield, code on main timeline -
    Code:
    function pad(num){ return ("0"+String(num)).substr(-2, 2); }
    
    function startT(){
    	d = new Date(); 	t0 = getTimer(); 	method = run;
    };
    
    function run(){
    	d.setTime(getTimer()-t0);
    	var h = pad(d.getUTCHours());
    	var m = pad(d.getUTCMinutes());
    	var s = pad(d.getUTCSeconds());
    	var ms = d.getUTCMilliseconds();
    	display = h+" : "+m+" : "+s+" : "+ms;
    };
    
    btnGo.onPress = function(){
    	method = startT;  
    };
    
    btnReset.onPress = function(){
    	method = null;  	display  = "00 : 00 : 00 : 000"; 
    };
    
    this.onEnterFrame = function(){
    	method();
    };
    
    startT();
    hth

  5. #5
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    865
    Hi! I've also got a timer thingy in my library, and Im attaching the same (F8).
    I've tested it's working OK. Thanks if you can plz comment on this guys/gals.
    Last edited by Eager Beaver; 08-19-2007 at 02:23 PM.

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