Hey all, I am stumped. I am trying to make my CountDownTimer component
as reusable as I can and I am stumped on how to pass a function
reference to it.

Here is what I want to do:

when the timer finally reaches the end, I want to fire a function that
is in the parent document so I can use my logic for when this event
occurs.

I have my custom event all registered and it fires when its supposed
to, but how the heck do I reference this outside function?

******************  CODE BELOW ********************************

package
{
        import mx.controls.Text;
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        import mx.utils.ObjectUtil;
        import flash.events.Event;
        
        public class CountDownTimer extends Text{
                public var minutes:Number=1;            
                public var seconds:Number=59;
                public var timedOut:Function;
                private var minuteDisplay:Number=minutes-1;
                private var zero:String="";
                private var newTimer:Timer;     
                
                public function CountDownTimer(){
                        super();                        
                }
                
                private function onTick(event:TimerEvent):String{
                        seconds--;
                        if(seconds < 10){
                                zero = "0";
                        } else {
                                zero = "";
                        }
                        
                        if(seconds == 30 || seconds == 0){
                                var n:Number;
                                var m:Number;
                                if(seconds == 0){
                                        n=59;
                                } else {
                                        n=30;
                                }
                                
                                if(minutes != 0 && seconds != 30){
                                        m=minutes-1;
                                } else {
                                        m=minutes;
                                }
                                
                                parentDocument.runUpdate(minutes,seconds);
                        }
                        
                        text = minutes + ":" + zero + seconds;
                        return text;
                }
                
                public function timerEnd(event:TimerEvent):void{
                        trace("timer ended");
                        if(minutes == 0 && seconds == 0){
                                text = "0:00";
                                newTimer.dispatchEvent(new 
Event("timerTimedOut"));
                                return;
                        }
                        startTimer();
                }
                
                public function startTimer():void{
                        if(seconds == 0){
                                seconds=59;
                        } else {
                                seconds = seconds;
                        }
                        minutes--;
                        newTimer = new Timer(1000,seconds);     
                        
newTimer.addEventListener(TimerEvent.TIMER_COMPLETE,timerEnd);
                        newTimer.addEventListener(TimerEvent.TIMER, onTick);
                        
newTimer.addEventListener("timerTimedOut",timedOutListener);
                        newTimer.start();       
                        trace("timer started");
                }
                
                public function stopTimer():void{
                        newTimer.stop();
                        trace("timer stopped");
                }
                
                private function timedOutListener(eventObj:Event):void{
                        trace("Timed out listener fired");
                        stopTimer();
                        //this is where I need to call the passed in function
                        //timedOut();
                }
        }       
}

thanks for any help!
-- 
I am not a diabetic, I have diabetes
my blog - http://grumpee.instantspot.com/blog

Reply via email to