The Timer class represents a timer for firing events at a specified interval.
// create a new instance of our timer class
// and start the application event loop
var t = new MyTimer;
Application.run();
// define our timer class
class MyTimer
{
function MyTimer()
{
// initialize a member variable to track the
// total amount of time that has elapsed once
// the timer is started
m_time_total = 0;
// initialize the interval in milliseconds at
// which to fire the timer event
m_time_interval = 100;
// create a new timer object, set it to fire the
// tick event at the specified interval, and connect
// the tick event to the onTick member function
m_timer = new Timer;
m_timer.setInterval(m_time_interval);
m_timer.tick.connect(this, onTick);
// start the timer
m_timer.start();
}
function onTick()
{
// ntoe: the onTick member function will be called
// everytime the specified interval has elapsed,
// which in this case is 100 milliseconds
// track the total time since the event
// started firing
m_time_total += m_time_interval;
// if 1 second has elapsed, stop the timer
// and issue an alert
if (m_time_total >= 1000)
{
m_timer.stop();
alert("1 second has elapsed");
}
}
// member variables
var m_time_total;
var m_time_interval;
var m_timer;
}
The time interval in milliseconds at which the the timer tick event is to be fired.
This function returns the time interval in milliseconds at which the timer tick event is to be fired.
True if the timer is running and false otherwise.
This function indicates whether or not the timer is currently running, and therefore, firing timer events. Returns true if the timer is running and false otherwise.
This function sets the time interval in milliseconds at which the timer tick event is to be fired.
This function starts the timer, so that the tick event is fired at a periodic interval.
This function stops the timer, so that the tick event stops firing.