Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Issues with stopping a timer via another function

Explorer ,
Jul 07, 2018 Jul 07, 2018

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();

                }

TOPICS
ActionScript
425
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 13, 2018 Jul 13, 2018

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();

                }}

              

fun

...
Translate
Community Expert ,
Jul 08, 2018 Jul 08, 2018

what are you trying to accomplish?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 13, 2018 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2018 Jul 13, 2018

how many timer's do you have?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 13, 2018 Jul 13, 2018

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2018 Jul 13, 2018

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();

                }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 13, 2018 Jul 13, 2018

i had tried .running before to no avail, that's actually why I ended up posting about this. Taking the variables and timer itself out of the function was just the trick! One of these days I'll figure it out.

Thanks, kglad!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2018 Jul 14, 2018
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines