Copy link to clipboard
Copied
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);
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();
}
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
...Copy link to clipboard
Copied
what are you trying to accomplish?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
how many timer's do you have?
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now