mardi 24 novembre 2015

Why are my timer and score count not working?

I am trying to create a game using action script 3 and can't understand why the following code is resulting in my score immediately resetting to 0 and my timer rapidly changing numbers with no consistent pattern? Any help is much appreciated! Thank You!

import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;

var score:int=0;
var nCount:Number = 5;
var myTimer:Timer = new Timer(3000, nCount);
timer_txt.text = nCount.toString();

myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();

function countdown(e:TimerEvent):void{
        nCount--;
        timer_txt.text = nCount.toString();
}
init();
function init(): void {
        Mouse.hide();
        addEventListener(Event.ENTER_FRAME, update);
        addEventListener(MouseEvent.CLICK, checkIfHit);
}

function update(myEvent:Event):void{
        aim_mc.x = this.mouseX;
        aim_mc.y = this.mouseY;
        score_txt.text = "Score: " + score;
}

function checkIfHit(e:MouseEvent):void{
        for(var i:int = 1; i < 4;++i){
                var myClip:MovieClip = MovieClip(getChildByName("duck" + i));
                if (myClip.hitTestPoint(mouseX,mouseY,true)){
                        score = score + 1;
                        
                }
        }
}

Aucun commentaire:

Enregistrer un commentaire