0
votes

Okay, i'm very new to Actionscript 3

I would like my timer to direct whoever is playing my game to go the 'Game Over' screen on timer completion (00:00). At the moment I am getting an error saying "1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject."

Any ideas?

package {

    import flash.display.MovieClip;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    public class SecondCounter extends MovieClip {

        private var myTimer:Timer=new Timer(1000,0);
        private var secs:Number=10;
        private var mins:Number=0;
        private var sec_t:String;
        private var min_t:String;
        var screen7:EndScreen;

        public function SecondCounter() {

            myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
            myTimer.start();
        }

        private function timerHandler(evt:TimerEvent):void {
            if (secs==0) {
                if (mins==0) {
                    addChild(EndScreen);
                } else {
                    mins--;
                    secs=59;
                }
            } else {
                secs--;
            }
            if(secs<10){
                sec_t = "0"+String(secs) 
            } else {
                sec_t = String(secs);
            }
            if(mins<10){
                min_t = "0"+String(mins) +":"
            } else {
                min_t = String(mins)+":";
            }
            secondField.text = min_t + sec_t;
        }
    }    
}
1

1 Answers

2
votes

The problem is that you are attempting to add the Class itself to the screen as opposed to an instance of the class.

 var screen7:EndScreen;
 // ....
 addChild(EndScreen);

EndScreen is the class. This is the blueprint of how to create an actual EndScreen object. Screen7 is an instance of the EndScreen class (EndScreen class = blueprint, screen7 instance = actual built house).

However you have not actually instaniated screen7, so do that:

var screen7:EndScreen = new EndScreen();

Now you can add that instance to the display:

addChild(screen7);