5 Replies - 889 Views - Last Post: 07 June 2017 - 12:24 PM

#1 cop77   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 31
  • Joined: 22-May 16

My counter is counting up instead of down?

Posted 07 June 2017 - 11:01 AM

My counter is counting up instead of down? I like it to count down from 10 minutes and when hours is 0 and minutes is 0 and seconds is 0 I want it to remove the counter and it should go to another frame using gotoAndStop(2).

var countdownTimer:Timer = new Timer(1000);
countdownTimer.addEventListener(TimerEvent.TIMER, updateTime);
countdownTimer.start();

var startTime:int = getTimer();
function updateTime(e:TimerEvent):void
{
	
	// milliseconds passed
	var timePassed:int = getTimer()-startTime;
	var seconds:Number = Math.floor(timePassed / 1000);
	var minutes:Number = Math.floor(seconds / 60);
	var hours:Number = Math.floor(minutes / 60);
	
	
	seconds %= 60;
	minutes %= 60;
	hours %= 24;
	
	var sec:String = seconds.toString();
	var min:String = minutes.toString();
	var hrs:String = hours.toString();
	
	
	if (sec.length < 2) {
		sec = "0" + sec;
	}
//A zero will automatic be put to the right side og 1, so "1" will be "10"
	if (min.length < 2) {
		min = "1" + min;
	}
	
	if (hrs.length < 2) {
		hrs = "0" + hrs;
	}
	
	var time:String = hrs + ":" + min + ":" + sec;
	
	time_txt.text = time;




Is This A Good Question/Topic? 0
  • +

Replies To: My counter is counting up instead of down?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • Joined: 12-June 08

Re: My counter is counting up instead of down?

Posted 07 June 2017 - 11:16 AM

Well, yeah. Look at how you are getting time.

10    var timePassed:int = getTimer()-startTime;


Say startTime is 20.
Gettimer is 20.
20 - 20 = 0

Gettimer is 21
21-20 = 1

Gettimer is 22
22-20 = 2

.. etc

When in doubt, write it out.

Perhaps set an 'endtimer' which would be the current time plus what ever you want.. like ten minutes.. and use that in the subtraction.
Was This Post Helpful? 0
  • +
  • -

#3 cop77   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 31
  • Joined: 22-May 16

Re: My counter is counting up instead of down?

Posted 07 June 2017 - 11:50 AM

Thanks but changing startTime to:
var timePassed:int = getTimer()+startTime;



give exactly the same result. It counts up instead of down.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • Joined: 12-June 08

Re: My counter is counting up instead of down?

Posted 07 June 2017 - 11:59 AM

No. That's not what I was getting at.

You have a start time and an ever increasing 'current time' that is moving away from it. That's wrong according to your needs.

What you want to is to go ten minutes out and count down to that, right? So no longer a 'start time' but an 'end time'. In this case the end time would be your 'start time' plus ten minutes. You would then use this 'end time' with your 'current time' and the appropriate math.
Was This Post Helpful? 0
  • +
  • -

#5 cop77   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 31
  • Joined: 22-May 16

Re: My counter is counting up instead of down?

Posted 07 June 2017 - 12:17 PM

It doesn't help. The result is the same if I change the startTime:
var startTime:int = 10; //getTimer();
function updateTime(e:TimerEvent):void
{
	
	// milliseconds passed
	var timePassed:int = getTimer()+startTime;


Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • Joined: 12-June 08

Re: My counter is counting up instead of down?

Posted 07 June 2017 - 12:24 PM

Again.. no. That is not what I outlined.

You want end time. Which would be the current time plus your 10 minutes. You didn't do that.
Would you be adding end time to the current time? No. I would subtract the current time from the end time.. you know as closer to 'end time' 'current time' is the smaller the number.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1