lundi 26 décembre 2016

Animate CC advances to the next frame with gotoAndStop commented out?

I'm writing this code that tests your reaction time and then advances to the next frame. It shows a box and then time the difference between when the box appeared and when the use presses [A]. Heer is my code

import flash.utils.Timer;
import flash.events.Event;
import flash.utils.getTimer;

stop();
        var canPress = false;
        var startClock:Timer = new Timer(4000+Math.random()*6000, 1);
        grbox.y = -500;
        startClock.start();
        var startTime:int = 0;

function displayBox(evt:Event):void{
        canPress = true;
        grbox.y = 143;
        var startTime:int = getTimer();
}

function Tpressed(e:KeyboardEvent):void
{
   if(e.keyCode==Keyboard.A){
                if(canPress==true){
                var endTime:int = getTimer();
                score1 = endTime-startTime;

                if(score2<0){
                        //gotoAndStop(3);
                }
                else{
                        //gotoAndStop(4);
                }
   }
   }

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, Tpressed);
startClock.addEventListener(TimerEvent.TIMER, displayBox);

For some reason if I just spam the [A] button it will advance to the next frame. Why is this happening?!?! My 'gotoAndStop(4);' command is commented out so it should do anything, yet it is.

Aucun commentaire:

Enregistrer un commentaire