Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Dec 28, 2013 Dec 28, 2013

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

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 28, 2013 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 28, 2013 Dec 28, 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];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 28, 2013 Dec 28, 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 29, 2013 Dec 29, 2013

Ned

i am a newbie to as3 and i did not quite understand what you exactly meant. so if you can kindly explain things in more detail.

what am i supposed to do with the below statement

var count:Number = 120;

am i supposed to rewrite it as

var count = Number(userTextfield.text);

is "userTextfield"  the instance name of the "inputTextfield" that  i am supposed to create for entering the number while the app is running

pls help

thank you very much



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 29, 2013 Dec 29, 2013

As far as

     var count:Number = 120;

goes you can leave that alone as a default starting value.

Use it as I showed in the button event handler function just before you start the countdown so that it reassigns it the value entered in the textfield.

Yes, userTextfield is the instance name I made up for the textfield you intend to use.  You can name it however you like.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 29, 2013 Dec 29, 2013

Ned

i am really sorry that i am still not able to get it straight

i hav captured a 1min 13 sec video and have uploaded on youtube (http://youtu.be/rkmO-LFh_aY) can u pls find some time to take a look at that video and tell me where exactly i am going wrong and how should i restructure my code

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 02, 2014 Jan 02, 2014

The error I see in your video is indicating it does not recognize a textfield named userTextField.  You need to assign that instance name to the textfield in order for it to be targeted.  Instance names are assigned by selecting the object on the stage and then entering the name in the Properties panel where it says <Instance name>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 03, 2014 Jan 03, 2014
LATEST

Dear Ned,

Thanks a million for guiding me into making things work....with your guidance and suggestions i have finally achieved what i have been trying to achieve....my workable code runs as follows:

var count:Number = Number(userTextField.text);

userTextField.restrict="0123456789";

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

countDown.addEventListener(TimerEvent.TIMER, countsdown);

countDown.stop();

function countsdown(event:TimerEvent):void

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

lev2StrtCountDwn.addEventListener(MouseEvent.CLICK, triggerLev2)

function triggerLev2(e:MouseEvent):void{

lev2StrtCountDwn.removeEventListener(MouseEvent.CLICK, triggerLev2);

count = Number(userTextField.text);

countDown.reset();  countDown.start(); userTextField.visible = true;

}

If you can help me with troubleshooting one more thing it would make things all the more perfect....

The code mentioned above allows me to set a "custom time" in the textfied and start the countdown timer but then the countdown keeps going down to negative values, i believe, without a restrictions....

So, how can i limit the countdown to "0"...should i be using an "if" statement or should i do something else. I tried the "if" statement and it does not work (perhaps due to wrong usage).

can you please help me with this.

Thanks a lot

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines