Hi everyone!
I developed a board game that has a timer in flash. This timer shows how much time they have left before the game stops.
The timer is working now, like it should. The only thing is that I would like a suprise element at a random moment
that will give the players an assignment. It should appear like a pop up screen and the timer have to stop playing
for a moment. At least, until someone press the spacebar. Then the pop up dissapears and the timer continues.
Can someone help me with that?
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.utils.setTimeout;
import flash.media.SoundChannel;
import flash.utils.*;
import flash.system.ImageDecodingPolicy;
import flash.display.BitmapData;
var customPanel:CustomPanel = new CustomPanel();
var timer:Timer = new Timer(30,0);
var timer2:Timer = new Timer(Math.random() * 1200000,1);
var myTimer:Timer = new Timer(1200000,1);
var secCntr:int = 0;
var minCntr:int = 40;
var hourCntr:int = 23;
var currentTime:String;
var soundRequest:URLRequest = new URLRequest(sounds/Flash Clock.mp3);
var mySound:Sound = new Sound();
var soundChannel1:SoundChannel = new SoundChannel();
mySound.load(soundRequest);
soundChannel1 = mySound.play();
timer.addEventListener(TimerEvent.TIMER, setTime);
timer2.addEventListener(TimerEvent.TIMER, surprise);
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
timer.start();
timer2.start();
function surprise(e:TimerEvent):void{
trace(Surprise!);
this.addChild(new CustomPanel());
}
function handleKeyDown(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.SPACE){
if(this.contains(customPanel)){
this.removeChild(customPanel);
}
}
}
function setTime(e:TimerEvent){
secCntr++;
if(secCntr == 60){
minCntr++;
secCntr = 0;
}
if(minCntr == 60){
hourCntr++;
minCntr = 0;
}
if (hourCntr >= 24){
hourCntr = 0;}
if(secCntr < 10){
currentTime = String(hourCntr) + : + String(minCntr) + :0 + String(secCntr);
}
else{
currentTime = String(hourCntr) + : + String(minCntr) + : + String(secCntr);
}
countdown_txt.text = currentTime
}
I'm not quite sure what I should add to make that happen.
I hope someone can help me!
Greets,
Anne-Loes
It's only been 10 minutes! The world is just waking up where most of the help comes from around here. By reposting you added 1 reply to your posting which can make your posting less visible... 0 replies draws attention.
What you might try is to break down that timer so that it deals with repeat counts so that you can stop it and restart it and get some semblance of the timing you intend. Maybe use something like...
var myTimer:Timer = new Timer(1000,1200);
Then you can stop() and start() it and it will resume to finish trhe number of repeats left.
North America
Europe, Middle East and Africa
Asia Pacific