I’ve been looking around all day and I can’t find anything on it so I’ve decided to make a thread here, sorry if I don’t explain things properly but i just took about 30 minutes writing all the information down and when I clicked create new thread it had logged me out as I had gone somewhere for half an hour in the middle of making the thread the first time.
I did try using the search function on these forums, but the things I found were a bit confusing for my stage in programming in as3.
I need to be able to take whatever time the stopwatch gets stopped at and put that into a text box with green and/or red text as well.
The stopwatch will eventually start when the player correctly presses a combination of keys within a certain time period, right now it’s just supposed to start when ‘a’ or ‘A’ is pressed. The stopwatch will eventually reset itself and continue counting when the player either successfully presses the keys within the time constaint, or fails to do so. Either way it will reset, and either way I need to be able to use the time that it was at just before it reset to show how close the player was to the perfect time.
Miliseconds are very important in this, infact the user more or less has to press a specific key between 640 and 647 milliseconds to do it at an acceptable level. The stopwatch needs to be in either an 00:000 or 00:0000 format, where the first 00 is seconds and the 000 or 0000 dependant on which format it’s in are the milliseconds.
Below is what I have so far, all you need to run it is a text field with an instance name of text_txt
What I have right now doesn’t work properly, I have to press ‘a’ twice to start the timer, ‘d’ twice to stop it, and ‘w’ twice to reset it. From what i see, I should only have to press it once.
Another issue with the code right now is after I’ve gone through the motions of either starting the timer, stopping it and resetting it, or starting then resetting, I can’t do anything else.
Any help would be appreciated, thanks! Please remember when you’re answering this that I’m extremely new at AS3, but have taken a couple Java courses in college as well as an html/javascript course.
text_txt.text = "0";
var myTimer:Timer=new Timer(1000,0);
myTimer.addEventListener(TimerEvent.TIMER, stopWatch);
function stopWatch(event:TimerEvent):void
{
text_txt.text=String(myTimer.currentCount);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case 65 ://A Key Pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN, startClock);
break;
case 68 ://D Key Pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN, stopClock);
break;
case 87 ://W Key Pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN, resetClock);
break;
}
}
function startClock(e:KeyboardEvent):void
{
myTimer.start();
}
function stopClock(e:KeyboardEvent):void
{
myTimer.stop();
}
function resetClock(e:KeyboardEvent):void
{
myTimer.reset();
text_txt.text="0";
}