# Timer Countdown Bar Script

**URL:** <https://forum.kirupa.com/t/timer-countdown-bar-script/319765>\
**Category:** flash\
**Created:** [March 3, 2011, 5:43pm UTC](https://forum.kirupa.com/t/timer-countdown-bar-script/319765 "2011-03-03T17:43:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![razzdesigns](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@razzdesigns](https://forum.kirupa.com/u/razzdesigns)\
**Post date:** [March 3, 2011, 5:43pm UTC](https://forum.kirupa.com/t/timer-countdown-bar-script/319765/1 "2011-03-03T17:43:39Z")

</div>

Hi all,

I have a script below which counts down and using the progress info makes a movieclip widen from nothing to its full width using the x scale.

This is being used for a countdown bar in my game so at the moment this bar movieclip is growing from nothing to its normal size. I want to reverse this so It starts at its normal size and grows smaller if you see what I mean.

A little example would be awesome 😃

(AS3)

Thanks

The script exists within 3 AS files,

Code in GameLevel.as:

```auto

var timer:ProgressTimer = new ProgressTimer(); 
			timer.addEventListener( ProgressTimerEvent.PROGRESS, onProgress ); 
			timer.start( 15000 ); 

			function onProgress( e:ProgressTimerEvent ):void 
			{ 
				trace( e.progress ); 
				 
				seismo.scaleX = e.progress;
				
			} 

```

Code in ProgressTimer.as:

```auto

package 
{ 
    import ProgressTimerEvent; 
     
    import flash.events.Event; 
    import flash.events.EventDispatcher; 
    import flash.utils.clearInterval; 
    import flash.utils.getTimer; 
    import flash.utils.setInterval; 
     
    public class ProgressTimer extends EventDispatcher 
    { 
        private var startTime:int = 0; 
        private var targetTime:int = 0; 
        private var interval:int = 0; 
        private var isRunning:Boolean = false; 
         
        public function ProgressTimer() 
        {} 
         
        public function start( time:int ):void 
        { 
            stop(); 
             
            startTime = getTimer(); 
            targetTime = startTime + time; 
            interval = setInterval( update, 30); 
            isRunning = true; 
        } 
         
        public function stop():void 
        { 
            if( isRunning ) 
            { 
                clearInterval( interval ); 
                isRunning = false; 
            } 
        } 
         
        private function update():void 
        { 
            var p:Number = getTimer() / targetTime; 
             
            if( p >= 1.0 ) 
            { 
                p = 1.0; 
                stop(); 
            } 
             
            var t:String = ProgressTimerEvent.PROGRESS; 
            dispatchEvent( new ProgressTimerEvent( t, p ) ); 
        } 
         
    } 
} 

```

and finaly from ProgressTimerEvent:

```auto

package 
{ 
    import flash.events.Event; 
     
    public class ProgressTimerEvent extends Event 
    { 
        public static const PROGRESS:String = "progress"; 
         
        private var _progress:Number = 0; 
         
        public function ProgressTimerEvent( type:String, progress:Number )
        { 
            super( type, false, false ); 
            _progress = progress; 
        } 
         
        public function get progress():Number // read-only 
        { 
            return _progress; 
        } 
    } 
} 

```

If anyone knows how to do this, your awesome.

Thanks!
