Skip to main content
cornbread02
Inspiring
July 8, 2018
Answered

Issues with stopping a timer via another function

  • July 8, 2018
  • 1 reply
  • 499 views

Hello,

So I am creating a quiz buzzer system in Flash.

My issue comes here: In one round, a player is given an obstacle of a half second delay before the buzz-in function activates. This works fine; however, if another player buzzes in, the slowed down player is still going through their buzz-in function and it wrecks my system reset. Below is my code that I altered to try to get this to work with one player before I try for all three—with a longer delay than what would be the final timer.

Penalized player has the event listener for standard buzz in (p1buzzin) replaced with a listener for a different function (p1Messed) that starts a timer (fTimer) and then does its own separate buzz-in function (p1buzzb).

I have a feeling that I am going about this the wrong way, but not sure how to rectify this. Any help would be appreciated!

RELEVANT CODE:
var fTimer: Timer = new Timer(2000, 1);

  1. fTimer.addEventListener(TimerEvent.TIMER_COMPLETE, p1buzzb);

function p1Messed(event: KeyboardEvent): void {

                if (buzzersActive == true && p1Buzz == false && event.keyCode == 37) {

                                fTimer.start();

                }}

               

function p1buzzb(event: TimerEvent): void {

                p1Buzz = true;

                buzzersActive = false;

                trace("Player 1");

                addChild(leftbuzz);

                ringin.play();

}

function checkTimer(): void {

                if (fTimer.start == true) {

                                fTimer.stop();

                }

}

function p1buzzin(event: KeyboardEvent): void {

                if (buzzersActive == true && p1Buzz == false && event.keyCode == 37) {

                                p1Buzz = true;

                                buzzersActive = false;

                                trace("Player 1");

                                addChild(leftbuzz);

                                ringin.play();

                }

}

function p2buzzin(event: KeyboardEvent): void {

                if (buzzersActive == true && p2Buzz == false && event.keyCode == 38) {

                                p2Buzz = true;

                                buzzersActive = false;

                                trace("Player 2");

                                addChild(cenbuzz);

                                ringin.play();

                                checkTimer();

                }

This topic has been closed for replies.
Correct answer kglad

Well, the final product would have two timers max. However, since I am not even sure if what I want to do is possible, I only tried it with one timer (the one you see in the code).


from your explanation, you have a lot of extraneous code but maybe later in your project you'll need some of that.

var alreadyExecuted:Boolean;

if(!alreadyExecuted){

var fTimer: Timer = new Timer(2000, 1);

fTimer.addEventListener(TimerEvent.TIMER_COMPLETE, p1buzzb);

alreadyExecuted=true;

}

function p1Messed(event: KeyboardEvent): void {

                if (buzzersActive == true && p1Buzz == false && event.keyCode == 37) {

                                fTimer.start();

                }}

              

function p1buzzb(event: TimerEvent): void {

                p1Buzz = true;

                buzzersActive = false;

                trace("Player 1");

                addChild(leftbuzz);

                ringin.play();

}

function checkTimer(): void {

                if (fTimer.running) {

                                fTimer.stop();

                }

}

function p1buzzin(event: KeyboardEvent): void {

                if (buzzersActive == true && p1Buzz == false && event.keyCode == 37) {

                                p1Buzz = true;

                                buzzersActive = false;

                                trace("Player 1");

                                addChild(leftbuzz);

                                ringin.play();

                }

}

function p2buzzin(event: KeyboardEvent): void {

                if (buzzersActive == true && p2Buzz == false && event.keyCode == 38) {

                                p2Buzz = true;

                                buzzersActive = false;

                                trace("Player 2");

                                addChild(cenbuzz);

                                ringin.play();

                                checkTimer();

                }

1 reply

kglad
Community Expert
Community Expert
July 8, 2018

what are you trying to accomplish?

cornbread02
Inspiring
July 13, 2018

Sorry for the delay.

For the love of me, I thought I had typed my actual question. My bad!

I thought that I had it coded so that player 2's button press should stop player 1's timer. However, the timer continues after the press and mucks up the whole swf. I'm trying to figure out why that is not working.

kglad
Community Expert
Community Expert
July 13, 2018

how many timer's do you have?