Sunday, June 24, 2012

[Action Script] Make countdown timer stop at 00:00:00 June,2012

Hey guys!
I hope that someone can help me out here!
I made a countdown in flash but it seems when it's ended it continues counting. How can I make it stop at 00:00:00

Here's my code:
ActionScript Code: import flash.utils.Timer;import flash.events.TimerEvent;import flash.utils.setTimeout;import flash.media.SoundChannel;import flash.utils.*;import flash.system.ImageDecodingPolicy;import flash.display.BitmapData;import flash.events.KeyboardEvent;import flash.display.DisplayObjectvar customPanel:CustomPanel = new CustomPanel();addChild(customPanel);var timer:Timer = new Timer(30,0);var timer2:Timer = new Timer(Math.random() * 60000,1);var myTimer:Timer = new Timer(1200000,0);var secCntr:int = 0;var minCntr:int = 40;var hourCntr:int = 23;var currentTime:String;var soundRequest:URLRequest = new URLRequest("sounds/Flash Clock.mp3");var mySound:Sound = new Sound();var soundChannel1:SoundChannel = new SoundChannel();mySound.load(soundRequest);soundChannel1 = mySound.play();timer.addEventListener(TimerEvent.TIMER, setTime);timer2.addEventListener(TimerEvent.TIMER, surprise);stage.addEventListener(KeyboardEvent.KEY_DOWN, pressedKey);timer.start();timer2.start();customPanel.visible = false;function surprise(e:TimerEvent):void    {    trace("Surprise!");    customPanel.visible = true;    }function pressedKey(event:KeyboardEvent):void{    if(event.keyCode == 32)            if(contains(customPanel))    {    this.removeChild(customPanel);    }        {    keyDetector()              }    }function keyDetector():void    {    trace("The spacebar key was pressed");    }        function setTime(e:TimerEvent){        secCntr++;    if(secCntr == 60)        {        minCntr++;        secCntr = 0;        }            if(minCntr == 60)        {        hourCntr++;        minCntr = 0;        }    if (hourCntr >= 24)        {        hourCntr = 0;}    if(secCntr < 10)        {        currentTime = String(hourCntr) + ":" + String(minCntr) + ":0" + String(secCntr);            }        else        {        currentTime = String(hourCntr) + ":" + String(minCntr) + ":" + String(secCntr);        }    countdown_txt.text = currentTime;     }
Hope someone can help me out.

Greets,
Anne-Loes
Make countdown timer stop at 00:00:00

Related Post



0 comments: