Skip to main content
Known Participant
December 28, 2013
Question

How can we set a "Custom Time" for count down timer ?

  • December 28, 2013
  • 1 reply
  • 1900 views

How can we create a count down timer in such a way that the time from which the countdown begins can be entered into a text field manually and when the start-countdown button is clicked the countdown begins from the manually entered time.  This is for an alphabet learning app for kids.

Please kindly demonstrate with procedural method and not OOP

thanks in advance

Message was edited by: shamse tabriz

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
December 28, 2013

Do you have something you are working on that you need help with or are you asking someone to design this for you?

If it is the former, show the code you have so far.  If it is the latter, find a design somewhere that you can use as a starting point and show the code and explain the different elements that you want to add/change.

Known Participant
December 29, 2013

Hello Ned

i am sorry that i did not include any code along with my question itself. Below is the related code.

//the timer in the App. has been currently set to two minutes (120 secs)

var count:Number = 120;

var countDown:Timer = new Timer(1000,count);

countDown.addEventListener(TimerEvent.TIMER, countsdown);

countDown.stop();

function countsdown(event:TimerEvent):void

{myText_txt.text = String((count)-countDown.currentCount);}

//when the strtCountDwn button is clicked -  apart from trigerring the timer a whole lot of events happen

// the entire Level Two of the app is trigerred by the removal of an "invisible shield" from the stage and giving access to click on the alphabet-blocks //(movieclips) on the stage in an orderly manner etc., etc.,

lev2StrtCountDwn.addEventListener(MouseEvent.CLICK, triggerLev2)

function triggerLev2(e:MouseEvent):void{

lev2StrtCountDwn.removeEventListener(MouseEvent.CLICK, triggerLev2);

shield.visible = false;

countDown.reset();  countDown.start(); 

lev2StrtCountDwn.visible = false; myText_txt.visible = true;

//.......somany events occur before the closing curly brace, but since they are not related to my question i have not included it here

}

//to stylize the font when the countdown starts i have added the below mentioned filters

var myPlayShadow2:DropShadowFilter = new DropShadowFilter();myPlayShadow2.distance = 4;

myPlayShadow2.color = 0x3F3F3F;          myPlayShadow2.blurX = 7; myPlayShadow2.blurY = 7;

myPlayShadow2.quality = 3; myText_txt.filters = [myPlayShadow2];

Ned Murphy
Legend
December 29, 2013

If the 'count' variable is the one that you wish to have set via a textfield where the user enters a value, then just assign it the value of the textfield .text property when the button is clicked that starts the Timer.  Since count is a Number, you just need to cast the .text value as a Number, as in...

count = Number(userTextfield.text);

You will probably want to test the textfield entry to make sure it is a valid numeric value and not blank or some other erroneous value (negative, alphabetic, etc)