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

How can i make this a 2 minute timer???

Community Beginner ,
Jan 26, 2011 Jan 26, 2011

package {

    import flash.display.MovieClip;

    import flash.events.TimerEvent;

    import flash.text.TextField;

    import flash.utils.Timer;

     import flash.text.TextFormat;

    public class timer2 extends MovieClip {

        private var textfield:TextField;

        public function timer2():void {

            var count:uint = 60;

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

            myTimer.addEventListener(TimerEvent.TIMER, countdown, false, 0, true);

            myTimer.start();

            textfield = new TextField();

          textfield.defaultTextFormat = new TextFormat("Arial", 24, 0xff0000, true);

          textfield.x = 30;

          textfield.y = 60;

            textfield.text = String(count);

            addChild(textfield);

        }

        private function countdown(e:TimerEvent):void {

            textfield.text = String(parseInt(textfield.text) - 1);

        }

    }

}

I have here a 1 min timer what I want is to make a 2 min timer with 2:00 format
can somebody help me??? Thnx in advance...

TOPICS
ActionScript
1.1K
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

correct answers 1 Correct answer

Community Expert , Jan 27, 2011 Jan 27, 2011
package {
   
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.utils.Timer;

    public class Timer2 extends Sprite {
       
        private var textfield:TextField;
        private var count:uint = 120;
       
        public function Timer2():void {
            var myTimer:Timer = new Timer(1000, count);   
            myTimer.addEventListener(TimerEvent.TIMER, count
...
Translate
Community Expert ,
Jan 26, 2011 Jan 26, 2011

:

package {

    import flash.display.MovieClip;

    import flash.events.TimerEvent;

    import flash.text.TextField;

    import flash.utils.Timer;

     import flash.text.TextFormat;

    public class timer2 extends MovieClip {

        private var textfield:TextField;

        public function timer2():void {

            var count:uint = 120;

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

            myTimer.addEventListener(TimerEvent.TIMER, countdown, false, 0, true);

            myTimer.start();

            textfield = new TextField();

          textfield.defaultTextFormat = new TextFormat("Arial", 24, 0xff0000, true);

          textfield.x = 30;

          textfield.y = 60;

            textfield.text = formatS(String(count));

            addChild(textfield);

        }

        private function countdown(e:TimerEvent):void {

            textfield.text = formatS(String(parseInt(textfield.text) - 1));

        }

private function formatS(s:String):String{

var n:int = int(s);

var min:int = Math.floor(n/60);

var sec:int = n-min*60;

var minS:String=String(min);

var secS:String=String(sec);

while(minS.length<2){

minS="0"+minS;

}

while(secS.length<2){

secS="0"+secS;

}

return minS+":"+secS;

}

    }

}


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
Community Beginner ,
Jan 26, 2011 Jan 26, 2011

Something is wrong with the code you gave the timer starts at 2:00 then as it counts it restarts from 0:01 then -1:59 and stuck up at -1:58?

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
Community Expert ,
Jan 27, 2011 Jan 27, 2011

this line:

textfield.text = formatS(String(parseInt(textfield.text) - 1));

should be:

textfield.text=formatS(String(120-e.target.currentCount));

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
Community Expert ,
Jan 27, 2011 Jan 27, 2011
package {
   
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.utils.Timer;

    public class Timer2 extends Sprite {
       
        private var textfield:TextField;
        private var count:uint = 120;
       
        public function Timer2():void {
            var myTimer:Timer = new Timer(1000, count);   
            myTimer.addEventListener(TimerEvent.TIMER, countdown, false, 0, true);
            myTimer.start();
           
            textfield = new TextField();
            textfield.defaultTextFormat = new TextFormat("Arial", 24, 0xff0000, true);
            textfield.x = 30;
            textfield.y = 60;
            textfield.text = format(count);   
            addChild(textfield);
           
        }
   
        private function countdown(e:TimerEvent):void {       
            textfield.text = format(--count);           
        }
       
        private function format(n:uint):String {
            return Math.floor(n/60) + ":" + (n % 60 < 10 ? "0" + n % 60 : n % 60);
        }
    }   
}
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
Community Beginner ,
Jan 27, 2011 Jan 27, 2011

tnx to all of you!!

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
Community Expert ,
Jan 27, 2011 Jan 27, 2011
LATEST

you're welcome.

p.s.  in the future, please mark helpful/correct answers.

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