Milliseconds And Timer
I'm trying to get the Timer class to run 1 time for 8000 milliseconds. But it goes way longer than expected.
ActionScript Code: function _timerHandler (event:TimerEvent) : void { switch(event.type){ case TimerEvent.TIMER: var _timeToAnswer = event.target.currentCount trace("MILLISECONDS: " + _timeToAnswer); break; case TimerEvent.TIMER_COMPLETE: _result = 'timedOut'; break; } } function _initTimer() : void { _questionTimer = new Timer(1, 8*1000); _questionTimer.addEventListener(TimerEvent.TIMER, _timerHandler); _questionTimer.addEventListener(TimerEvent.TIMER_COMPLETE, _timerHandler); _questionTimer.start(); }
_questionTimer = new Timer(1000, 8); works great. but if i want track milliseconds it goes way too long.
thanks for the help
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 10-05-2008, 07:03 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Timer Problem With Seconds / Milliseconds
hi people!
im using this script i found for a racing game lap counter:-
onClipEvent (enterFrame) {
if (start) {
_root.elapsedt = Math.round((getTimer()-start)/100)/10;
}
if (this.hitTest(_root.car)) {
if (_root.lastc == 3) {
_root.laps++;
_root.lastc = 0;
if (start) {
_root.lastlapt = Math.round((getTimer()-start)/100)/10;
if (_root.lastlapt<_root.bestlapt) {
_root.bestlapt = _root.lastlapt;
}
}
start = getTimer();
}
}
}
It works great but id like it to count centiseconds also ie 10.23 instead of just 10.2 like it would do now
Cheers
M
Actionscript To Convert Milliseconds Into Timer
Hello.
Is there any way one could convert any given time (time in milliseconds) from milliseconds in hours, minutes, seconds and milliseconds in Flash 8?
If so, can anyone help with the actionscript to accomplish the following: actionscript to display any given milliseconds in hours, minutes, seconds and milliseconds eg, 0:00:00:00 ?
Thanks,
MM
Milliseconds
does any body tell me
how many milliseconds is equal to one sec.
How To Work With Milliseconds ?
I've made a countdown timer (to count down to my graduate). It works fine, except to slow .... cause the lowest time measure is in seconds.
I want to add milliseconds to it, but I really don't know how to do it. Can someone help ?
Thanks
Displaying Milliseconds On Mac
Just wondering fi anyone new how to get the Milliseconds to display on a Mac. I can display them on a PC with the exact same scripting. The script is in a blank movieclip with an onClipEvent(enterFrame). Anyone have any ideas?
Getting Date Using Milliseconds
Date.setTime
Availability
Flash Player 5.
Usage
myDate.setTime(millisecond)
Parameters
millisecond An integer value where 0 is 0:00 GMT 1970 Jan 1.
Returns
An integer.
Description
Method; sets the date for the specified Date object in milliseconds since midnight on January 1, 1970, and returns the new time in milliseconds.
-----
If I have a number that is the number of milliseconds since Jan 1 1970 at a certain point in time, and I want to simply get a date back from that... what do i have to do?
Thanks
Shoebox
Calculating Milliseconds
HI, hopefully a simple one, i've got a script that does a countdown, all works fine but i'd like to add a milliseconds text box too - to show a milliseconds countdown.
The script I use for the others is as follows:
Days = Math.round(Time /(60*60*24)-0.5) ;
Hours = Math.round(Time /(60*60) -(Days*24)-0.5) ;
Minutes = Math.round(((Time /60)-(Days*24*60)- Hours*60)-0.5) ;
Second = Math.round(((Time)-(Days*24*60*60)- (Hours*60*60) - (Minutes*60))-0.5) ;
This works fine, i'd just like to know what the line is that I need to add for a milliseconds calculation.
Thanks
SetInterval In Milliseconds?
hello
I worte some script using setInterval for displaying a timer using miliseconds and seconds that can be stopped and started and reset after pressing a button.
I was under the impression that setInterval worked indepentantly of frame rate.. and the number you set in the setInerval function is in miliseconds.. but it deosnt matter what I do I can not get it to display milliseconds it is always too slow..
Advice anyone?
Controlling Flv With Milliseconds?
When working with flv files, is there a way to get a millisecond duration & position, similar to working with audio files (mySound.duration and mySound.position return milliseconds).
I’m using NetStream and looking to control play/pause/seek functions within 10-20 millisecond window in order to accurately and dynamically attach sound objects to a flv.
But everything I’ve found so far controls flv videos by seconds rather than milliseconds. Any ideas?
Question About Milliseconds
lets say there are two computers. One really really fast and one very very slow.
they both load up the same .swf file. If if they have preloaders would the slow computer run the .swf slower than the fast computer?
I have this button and it will not perform an action until 200milliseconds later. This is very important for an effect. would this mean that on a fast computer the action will be performed too quicky and on a slow computer too slowly?
Converting Milliseconds
Hey all,
Does anyone know how to convert milliseconds to a format of
minute: seconds ex... 3: 23
Thanks...
Question About Milliseconds
lets say there are two computers. One really really fast and one very very slow.
they both load up the same .swf file. If if they have preloaders would the slow computer run the .swf slower than the fast computer?
I have this button and it will not perform an action until 200milliseconds later. This is very important for an effect. would this mean that on a fast computer the action will be performed too quicky and on a slow computer too slowly?
Converting Milliseconds
Hey all,
Does anyone know how to convert milliseconds to a format of
minute: seconds ex... 3: 23
Thanks...
NetStream.time() To Milliseconds
I'm trying to do a video counter and netStream.time() function gives me the the position of the playhead, in seconds. Now I also want to try and get the position of the playhead in milliseconds.
How can I get this from netStream.time()
Thanks
[help] Changing Milliseconds On SetInterval()
Hi: i'm wondering if it's possible to change the milliseconds on a currently running setInterval. i have the following:
code:
frec = 1;
_global.initEne = function() {
setInterval(juego,(1000*frec));
updateAfterEvent();
};
juego = function () {
//code too long and maybe confusing, irrelevant to this question
bla bla;
}
_global.golpJug = function() {
_root.frec -= 0.1;
};
initEne();
then in a button i have:
code:
on (release) {
golpJug();
}
but the interval doesn't change. I assume is because it doesn't read again the milliseconds variable in each iteration, but then, how can i tell it to change?
Any ideas most appreciated
Cheers
Sir Patroclo
Measuring Time In Milliseconds
Hi,
I've got a project here that I need measure response times of button clicking.
It needs to be millisecond accurate though.
From what I can gather, Flash can only go up to 120 fps so I can only measure up to 120/1000 of a second
i.e. approx 1/10th of a second.
Is there any other way I could do this?
I would rather not run anything at 100 fps!
Thanks for your help in advance.
Alex
Finding Time From Milliseconds
I want to measure how long a player has been playing my game in hours, minutes, seconds, and milliseconds and put it in a text field. Does this do the trick?
ActionScript Code:
//Display in hours, minutes, seconds, and milliseconds in a text field
time = getTimer();
totalGameTime = time-_global.myGameTime;
mils = totalGameTime%1000;
seconds = Math.round(((totalGameTime-mils)/1000)%60);
minutes = Math.round((((totalGameTime-seconds)/1000)/60)%60);
hours = Math.round(((((totalGameTime-minutes)/1000)/60)/60)%24);
time_txt.text = "Time: "+hours+": "+minutes+": "+seconds+": "+mils;
Animation Based On Milliseconds
HI,
I'm having trouble solving an animation problem.
I've got a movie clip of a speaker that is 10 frames long. (An arbitrary value I pulled from nowhere). The animation of the speaker simply goes from small to large to simulate it pulsing or pounding.
I'm trying to find a way to get the speaker to animate every 431 milliseconds for a duration or 431 milliseconds or less. The value of 431 can change and be a value of X.
So in reality I need to get the speaker to animate every X milliseconds for a duration of X milliseconds or less
Any insight on how to approach this problem?
Thanks,
dub
SetInterval - Time In Milliseconds?
When using setInterval, timing is in milliseconds, correct? If I have a movie that is 2 minutes and 42 seconds long and I want it to load another movie when it is finished playing, that would be 162 seconds before I want the second movie loaded.
So I would use 162,000 as the interval timing value right? Or am I going crazy...
Okay I may be going crazy regardless...
Formula To Calculate Milliseconds?
I'm creating a count down timer to a specific date, and I have the hour, min, secs and days calculated but I just can't get the formula for milliseconds. Can someone please help. Thanks
Stop Sound After X Milliseconds
Hi,
I'm trying to build sort of a virtual piano, with a recording option. I'm at the stage where I can record the keys pressed and the number of milliseconds they have been pressed. I put that information into two arrays: keyArray and the timeArray. What I now want to do is go through the keyArray and play the sound attached for the number of milliseconds that are in the timeArray.
So basically the question is, how can I run an event for a fixed number of milliseconds, where the milliseconds can change after each event?
Display Time Left In Milliseconds
Hello!
First off I forgot to thanks for the answer of my previous question so I'll thank you here! (Sorry I don't really think I should bump a thread for just a thanks)
I'm further along on my math program and now I have a problem. I'm trying to display the amount of time left. My problem is that displaying the numbers slower than the real time. This is true for the tenth, hundredth, and thousandth second.
Here's my general approach to it. The code is a little messy.
ActionScript Code:
timer = timer*1000; //timer is how long you have to answer a question
var timeLeftTimerTen:Timer = new Timer(100, 0);
var timeLeftTimer:Timer = new Timer(1000, 0);
var secHundredCounter:int = 0;
var secThousandCounter:int = 0;
timeLeftTimer.addEventListener(TimerEvent.TIMER, timerLeft);
timeLeftTimer.start();
timeLeftTimerTen.addEventListener(TimerEvent.TIMER, timerLeftTen);
timeLeftTimerTen.start();
function timerLeft(event:TimerEvent):void
{
secCounter++ ;
secAmount = (timer/1000) - secCounter;
displaySec_txt.text = String(secAmount);
if (secCounter*1000 == timer)
{
secCounter = 0;
secTenCounter = 0;
timeLeftTimer.reset();
timeLeftTimerTen.reset();
}
}
function timerLeftTen(event:TimerEvent):void
{
secTenCounter ++;
secTenAmount = (timer/100 - secTenCounter) - (10*Math.floor((timer/100 - secTenCounter)/10));
displaySecTen_txt.text = String(secTenAmount);
}
The code works but displaying the numbers are not in sync. In theory every time the secTenAmount is 0 the secAmount should decrease by one. This doesn't show though. The problem is that flash can only display/change text so fast on the go, I think. Is there another approach to this? I've seen stopwatch before that display milliseconds perfectly, like this.
Many thanks : )
Converting Milliseconds To Hours And Minutes
I have 2 Date objects and count down from now to ready,
and show it in the format of "00 HOURS and 00 MINS."
Code:
var now:Date = new Date();
var ready:Date = new Date(2008,9,10,12,0,0);
var dif:Number = (ready.valueOf() - now.valueOf());
trace(dif);
How can I convert difference to HOUR + MIN?
Please help.
P.S. I`m using A.S. 3.0
Converting Milliseconds To Hours And Minutes
I have 2 Date objects and count down from now to ready,
and show it in the format of "00 HOURS and 00 MINS."
Code:
var now:Date = new Date();
var ready:Date = new Date(2008,9,10,12,0,0);
var dif:Number = (ready.valueOf() - now.valueOf());
trace(dif);
How can I convert difference to HOUR + MIN?
Please help.
P.S. I`m using A.S. 3.0
Converting Milliseconds To Hours And Minutes
I have 2 Date objects and count down from now to ready,
and show it in the format of "00 HOURS and 00 MINS."
Code:
var now:Date = new Date();
var ready:Date = new Date(2008,9,10,12,0,0);
var dif:Number = (ready.valueOf() - now.valueOf());
trace(dif);
How can I convert difference to HOUR + MIN?
Please help.
P.S. I`m using A.S. 3.0
Converting Milliseconds Into Minutes/seconds Format
Does anyone have a function handy that converts milliseconds into a user friendly minutes/seconds format? (4:34, for example)
I can probably do this on my own, but it would take some time and I figure somebody else has had to do this at some point...
(frame Rates) Milliseconds - To - Seconds Conversion
Hi-
I have just conducted an unsuccessful search for a simple conversion table to have as a reference for when I need to apply multiple and different intervals within an app. I realize that with the nature of Flash and computer processors it's all relative, however I would still like to have something approximate to refer to so I can tell my client, "oh sure I can change that interval to 60 seconds"...and be able to plug in the closest millisecond equivelant.
Here's an example of what I'm looking for:
At 30 fps - 5 second interval = 1000 (ms)
At 30 fps - 30 second interval = 50000 (ms)
...these are just guesses, but hey, am I even close? Thanks in advance for your help.
Difference Between Timer.stop() And Timer.reset()?
Hello,
What is the difference between Timer.stop() and Timer.reset() functions because it seems that the 2 functions do the same thing? I image Timer.stop() to stop the timer and when Timer.start() is called the timer starts from where it stopped. For example, if I have a 3 sec. timer (3000 ms). If I stop the timer after 2.5 sec. and start the timer again, I would expect the timer to expire/trip within .5 sec. Is this a correct assumption?
Thanks,
Nilang
Difference Between Timer.stop() And Timer.reset()?
Hello,
What is the difference between Timer.stop() and Timer.reset() functions because it seems that the 2 functions do the same thing? I image Timer.stop() to stop the timer and when Timer.start() is called the timer starts from where it stopped. For example, if I have a 3 sec. timer (3000 ms). If I stop the timer after 2.5 sec. and start the timer again, I would expect the timer to expire/trip within .5 sec. Is this a correct assumption? Code is attached below.
Thanks,
Nilang
Attach Code
// Declarations
var url:URLRequest;// Url
var snd:Sound;// Sound Object
var sndChan:SoundChannel;// Sound Channel Object
var sndPosition:Number;// File offset
var tmr:Timer;// Timer object
var isPlaying:Boolean;// Flag to indicate whether file is
// playing or not
var isPlayDelayed:Boolean;// Flag to indicate whether starting
// of file has been delayed or not
var hours:Number = 0;// Hours
var minutes:Number = 0;// Minutes
var seconds:Number = 0;// Seconds
var milli:Number = 0;// Milliseconds
var pauseTime:Number = 0;// Time when paused
var pauseLength:Number = 0;// Length of pause
var buttonPressTime:Number = 0;//
var timing:Boolean = false;// Flag
// Initialize variables.
isPlaying = false;
isPlayDelayed = true;
sndPosition = 0;
// Get url
url = new URLRequest("sound1.mp3");
// Create new Sound object
snd = new Sound();
// Create new SoundChannel Object
sndChan = new SoundChannel();
// Create a new Timer Object with timeout of 5 sec.
// and repeat it only once.
tmr = new Timer(5000, 1);
// Load the audio file
snd.load(url);
// Enable Event Listeners
tmr.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
stop_btn.addEventListener(MouseEvent.CLICK, onStop);
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
this.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
// Start time
pauseElapsedTime(false);
// Start Timer
tmr.start();
// Function that handles timer events
function onTimerComplete(e:TimerEvent):void
{
// Play audio file when timer complete event is received
sndChan = snd.play(sndPosition);
// Set the isPlaying to true to indicate file is playing
isPlaying = true;
// Set the isPlayDelayed to false
isPlayDelayed = false;
trace("onTimerComplete: " + e);
trace("target: " + e.target);
trace("current target: " + e.currentTarget);
}
// Function that captures frame events
function onEnterFrameHandler(e:Event):void
{
// Local variables
var totalTime:Number = (getTimer()/1000)-pauseLength;
var goTime:Number = totalTime-buttonPressTime;
// If flag is true, then calculate the time that has elapsed
if( timing )
{
// Calculate time
hours = Math.floor(goTime/3600);
minutes = Math.floor((goTime/3600-hours)*60);
seconds = Math.floor(((goTime/3600-hours)*60-minutes)*60);
milli = Math.floor((goTime-(seconds+(minutes*60)+(hours*3600)))*100);
// Display elapsed time
timeText.text = format(hours) + ":" + format(minutes) + ":" + format(seconds) + "." + format(milli);
}
}
// Function that captures mouse click events when user clicks stop button
function onStop(me:MouseEvent):void
{
// Reset time
restartElapsedTime();
if (isPlaying)
{
// If audio file is playing then stop the audio file, set file offset to zero,
// and set isPlaying flag to false
sndChan.stop();
sndPosition = 0;
isPlaying = false;
isPlayDelayed = true;
}
else if (isPlayDelayed)
{
// If audio playback is delayed then reset the timer and
// set isPlaying to false
tmr.reset();
isPlaying = false;
}
}
// Function that captures mouse click events when user clicks pause button
function onPause(me:MouseEvent):void
{
// Pause time
pauseElapsedTime(true);
if (isPlaying)
{
// If audio file is playing then stop the audio file,
// set file offset to current offset, and set isPlaying flag to false
sndChan.stop();
sndPosition = sndChan.position;
isPlaying = false;
}
else if (isPlayDelayed)
{
// If audio playback is delayed then stop the timer and
// set isPlaying to false
tmr.stop();
isPlaying = false;
}
}
// Function that captures mouse click events when user clicks play button
function onPlay(me:MouseEvent):void
{
// Start time
pauseElapsedTime(false);
if (!isPlaying)
{
if (!isPlayDelayed)
{
// If the audio file is not playing and playback is not delayed, then
// play the audio file from the last offset and set isPlaying to true
sndChan = snd.play(sndPosition);
isPlaying = true;
}
else
{
// If the audio file is not playing and playback is delayed, then
// start the timer and set isPlaying to false
tmr.start();
isPlaying = false;
}
}
}
// Function that sets the time to 00:00:00.00 (default)
function restartElapsedTime():void
{
timeText.text = "00:00:00.00";
buttonPressTime = (getTimer()/1000)-pauseLength;
pauseElapsedTime(true);
}
// Function that pauses time
function pauseElapsedTime(b:Boolean):void
{
if( b )
{
pauseTime = getTimer()/1000;
}
else
{
pauseLength = ((getTimer()/1000)-pauseTime)+pauseLength;
}
timing = !b;
}
// Function adds 0 to the front of the number when it is < 10 and
// returns a String
function format(n:Number):String
{
if( n < 10 )
{
return ("0"+n);
}
return n.toString();
}
Timer - Not Timer Class, But Time Taken To Do Certain Events
So i'm making a little game and want to know how to start a timer and display the number of milliseconds between the start and finish of two different events. I do not want to run a function after 5000 milliseconds or whatever, just record the length of time taken to say click two buttons.
Basically a stopwatch.
I saw the getTimer(); function but i'm not sure of how to use it or if that is what i need.
Once again, thanks for your time.
How To Create "elapsed" Time Clock W/ Minutes/seconds/milliseconds
I would like to add a timer (not a countdown) in my animation that starts from zero, has a format like 00:00:00 and goes until a certain frame then stops. ACTUAL/ACCURATE time elapsed isn't so important as the action of time passing. As long as it is close and relatively believeable.
Can anyone help?
-Julie
Running Timer And Timer With Offset
Hello all,
I'm trying to set up two timers in that dare feed the time in minutes and seconds from the server.
Basically, I've got a master running timer in seconds and minutes but also want to have a second cloned timer that is feed some seconds via flashVars to add to the the master time.
Both of these timers once set by the sever time feed in, and with one being offset, are called every second by a setInterval function call so they count up.
Setting up the master running timer isn't a problem but with my coding skills is a little messy..
Code:
_global.masterRunningTimeInMinutes = 59;
_global.masterRunningTimeInSeconds = 55;
if (_global.masterRunningTimeInSeconds>0 && _global.masterRunningTimeInSeconds<59) {
_global.masterRunningTimeInSeconds++;
} else {
_global.masterRunningTimeInSeconds = 0;
_global.masterRunningTimeInSeconds++;
if (_global.masterRunningTimeInMinutes>=0 && _global.masterRunningTimeInMinutes<=58) {
_global.masterRunningTimeInMinutes++;
} else if (_global.masterRunningTimeInMinutes>=59 && _global.masterRunningTimeInSeconds>=0) {
_global.masterRunningTimeInMinutes = 0;
}
}
if (_global.masterRunningTimeInSeconds<10) {
_global.masterRunningTimeInSeconds = "0"+_global.masterRunningTimeInSeconds;
}
_root.runningTime.text = "v"+_global.masterRunningTimeInMinutes+":"+_global.masterRunningTimeInSeconds;
Ideally I wanted to to get the master running time to display MM:SS so if anyone can help with that that would be great!
I suppose the real problem I'm having is is setting up the pattern for determining the cloned time with the offset.
This is becoming a real headache but if anyone can help I would really appreciate it! Basically I just wanted to have the running time with the cloned time always a certain amount of seconds ahead.
Many thanks, amp3
Timer.
Hi, I am having problems with a timer.
Using the code from one of the movies here on Flashkit, I wanted to add 100th seconds to the movie. Here's the code:
millitime = getTimer()/60000-(int(getTimer()/60000));
seconds = (int(millitime*60));
milli = (int(millitime*6000));
mymin = (int(getTimer()/60000));
if (seconds <10) {
seconds = "0" + seconds;
}
if (Number(mymin)<1) {
mintime = "00";
} else {
mintime = (int(getTimer()/60000));
if (Number(mymin)<10) {
mintime = "0" + mintime;
}
}
minfield = mintime;
As you can see 'milli' is the amount of milliseconds in a minute, and I am unsure as to how to get this to read 00 - 99 in a single field and then restart after 1 second. HELP?
G
Timer
Let's say I have this timer:
timer = int ((getTimer ())/60000)
When I go to the next frame/stage I want the timer to "reboot". So I thought, why not do this:
timer = int ((getTimer ())/60000)
timer2 = int ((getTimer ())/60000)
And in the next frame/stage:
timer = int ((getTimer ())/60000 - timer2)
But all I get is the same value. At first I thought that If a put a, for example, getTimer value in a var, then it remains constant, keep the same value that the timer had in that specific time. And therefor should my script work, but it doesn't. Why?
Timer
Hello, i have a question.
How can i insert a visible countdownb timer (20 seconds) in my flash movie and when the timer = 0 i want a certain script to be executed????
sorry for my bad English
Help With Timer
Hi,
I have posted this problem before but I still can't fix it.
problem:
I want a clock in milliseconds to start on a specific frame and end it on another.
With getTimer() I can't get the clock to start on a frame. It always starts on frame 1 of the main timeline.
PLZ does anyone know a solution ?
Timer
How do you make a timer so that I can set a number of seconds before going to the next frame?
Thanks
Set A Timer
is there a way to tell a movieclip wait 10 seconds and then goto a certain frame number and play.
Like you just want the moieclip to wait 10 seconds before it restarts.
Timer
How could I program a timer to count down from 3 and then go to the next frame?
I'm sure it's simple, but I can't program for crap
Timer
I have 5 questions in my flash.
I'd like to create a timer that counts how long it takes to answer. How could I do that?
How To Set The Timer
well i have got a sort of a traffic light and i want each light to be displayed exactly after 4 secs. how do i write a code to do it ??can anyone plz help me ????
Timer
Im using this code to time 30 seconds I know its wrong and would really appreciate help
In the first frame i have
startTime = getTimer ();
then the next
newTime = getTimer();
if ((newTime/1000)-(startTime/1000)>30) {
_root.gotoAndPlay("10");
} else {
gotoAndPlay (2);
}
_root.showTime = (newTime/1000)-(startTime/1000);
Timer
Hi there!
How do I stop in a frame lets say in 5 sec. and then gotoAndPlay the next frame?
Thanx
SAM
Timer
hi.
i want this function to repeat itself only every two seconds. how do i do that? a "do while" loop using getTimer?
function playBack (note) {
for (i=0; i<musicList.length; i++) {
fscommand ("player1.playNote", musicList[i]);
}
i'm pushing a bunch of notes to an array, and then i want them played back, but i want a little space between them, so they don't play back all at once (which is what they're doing now).
|