In your example, seconds doesn't really mean anything. 60 seconds plus 10 
seconds should never equal 70 seconds - you want it to equal 10 seconds.

Maybe try...

var seconds = 10;
var now = new Date();
var future = new Date();
future.setSeconds ( now.getSeconds() + seconds ); // will auto adjust the time
trace( 'now: ' + now )
trace( 'future: ' + future )
trace( 'time is up: ' + (now.getTime() > future.getTime()) )



I found it better to use Date.getTime() and work with the milliseconds, like;


//
//              TIME VERSION
//

var timeoutInterval:Number;
var seconds:Number = 3;
var now:Number = getTimer();

function startTimer ( time:Number ) {
        timeoutInterval = _global.setTimeout ( this, 'onTimesUp', time * 1000 );
}

function clearTimer ( ) {
        _global.clearTimeout ( timeoutInterval );
}

function onTimesUp ( ){

        trace( ' \n onTimesUp \n' )

        var then = now/1000;
        var now = getTimer()/1000;

        trace( 'TIME VERSION ::  then: ' + then + ' now: ' + now + ' = ' + 
(now-then) );


        var nowD:Date = new Date( );
        var timechange = futureD.getTime( ) - nowD.getTime( );

        trace( 'DATE VERSION ::  timeup: ' + (timechange<0) + ', ' + 
(timechange/1000) + ' seconds ago' );
}

startTimer ( seconds );



//
//              DATE VERSION
//

var nowD:Date = new Date( );
var futureD:Date = new Date ( (seconds*1000) + nowD.getTime( ) );
var timechange = futureD.getTime( ) - nowD.getTime( );

trace( 'nowD: ' + nowD );
trace( 'futureD: ' + futureD );
trace( 'timechange: ' + (timechange/1000) + ' seconds' );
trace( 'time up: ' + (timechange<0) )




-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gustavo Duenas
Sent: Friday, March 23, 2007 12:29 PM
To: Flashcoders mailing list
Subject: [Flashcoders] timer question

Hi, I'm trying to launch an event using a timer so far the code for
trace something is this:

var now = new Date();

var seconds:Number = now.getSeconds();

trace(seconds);

var newSeconds: Number = seconds+10;

if ( seconds == newSeconds){
        trace("plus 10");
}

var seconds:Number = seconds;



the problem is that this ones doesn't trace" plus 10", instead just
traces the var seconds.

Do you know what is wrong here?


Regards.



Gustavo Duenas

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to