Title: RE: [flexcoders] Timers

Hi,

Using Timer class is simple:

import flash.util.Timer;

var timer:Timer = new Timer(500);
timer.addEventListener(TimerEventType.TIMER, handleTimerEvent);

private function handleTimerEvent(event:TimerEventType)
{
        //your code

        if(condition)
        {
                //to stop timer
                timer.stop();
        }
}

Timer.start();

FlexBuilder 2 comes with help. FYI, I am copying pasting Timer class documentation below:


-abdul


flash.util
Class Timer
Object
    |
    +--flash.events.EventDispatcher
         |
         +--flash.util.Timer


public class Timer
extends
EventDispatcher
The Timer class is the interface to Flash Player timers. You can create new Timer objects to run code on a specified time sequence. Use the start() method to start a timer. Add an event listener for the "timer" event to set up code to be run on the timer interval.

Click here to view the Examples




Property Summary               
       
delay : Number
The delay, in milliseconds, between timer events.      
       
repeatCount : uint
The total number of times the timer is set to run.     
       
running : Boolean [read-only]
true if the timer is running.  

Properties inherited from class Object 
prototype      



Event Summary          
timer   A Timer object generates the timer event whenever a timer tick occurs. 



Constructor Summary            
       
Timer(delay:Number, repeatCount:uint = 0)
Constructs a new Timer object with the specified
delay and repeat state.       



Method Summary         
       
restart() : Void
Restarts the timer.    
       
start() : Void
Starts the timer, if it is not already running.
       
stop() : Void
Stops the timer.       

Methods inherited from class EventDispatcher   
addEventListener, dispatchEvent, hasEventListener, removeEventListener, toString, willTrigger  

Methods inherited from class Object    
hasOwnProperty, isPropertyEnumerable, isPrototypeOf, valueOf   



Property Detail        

delay Property
public delay : Number
The delay, in milliseconds, between timer events.


repeatCount Property
public repeatCount : uint
The total number of times the timer is set to run. If the repeat count is set to 0, the timer continues forever (or until the stop() method is invoked or the program stops). If the repeat count is nonzero, the timer runs the specified number of times.


running Property
public running : Boolean [read-only]
true if the timer is running. false otherwise.


Event Detail           

timer Event
Type : TimerEventType
A Timer object generates the timer event whenever a timer tick occurs.
This event has the following characteristics:

Characteristic  Description    
Target  The Timer object that generated this event.    
Default Behavior        None.  
Bubbles No.    
Cancelable      No. There is no default behavior to cancel.    
Objects that generate this event        Timer. 
Replaces ActionScript 2.0 event(s)      None, this event is new.       
Example listener function      
function timerListener(event:TimerEvent) {
trace(event.type); // output: timer
}
      
Example addEventListener() call someEventDispatcher.addEventListener(TimerEventType.TIMER, timerListener);     
See also

        flash.events.TimerEvent



Constructor Detail             
Timer Constructor

public Timer(delay:Number, repeatCount:uint = 0)
Constructs a new Timer object with the specified delay and repeat state.
The timer does not start automatically; you much call the start() method to start it.
Parameters
        delay:Number The delay between timer events, in milliseconds.
               
       
repeatCount:
uint (default = 0) Specifies the number of repetitions. If zero, the timer repeats infinitely. If nonzero, the timer runs the specified number of times and then stops.  
Throws

        Error if the delay specified is negative or not a finite number      



Method Detail          

restart Method
public restart() : Void
Restarts the timer. The timer is stopped, and then started.


start Method
public start() : Void
Starts the timer, if it is not already running.


stop Method
public stop() : Void
Stops the timer.


Example

package {
        import flash.util.trace;
        import flash.util.Timer;
        import flash.events.TimerEvent;
        import flash.display.Sprite;

        public class TimerExample extends Sprite {

                public function TimerExample() {
                        var myTimer:Timer = new Timer(1000, 2);
                        myTimer.addEventListener("timer", onTimer);
                        myTimer.start();
                }

                public function onTimer(event:TimerEvent):Void {
                        trace("onTimer: " + event);
                }
        }
}




 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Greg Johnson
Sent: Thursday, October 20, 2005 9:19 AM
To: [email protected]
Subject: [flexcoders] Timers

Can someone point me to where I can get info on the Timer Class.  The
livedocs just ether say see the new Timer Class, or for the Timer Class
it just says TBD :/





------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to