Dana Vrajitoru
B583/C490 Game Programming and Design

Timer in ActionScript

General Description

Example

import flash.utils.Timer;
import flash.events.TimerEvent;

tileTimer = new Timer(700); // in miliseconds
tileTimer.addEventListener(TimerEvent.TIMER, removeTiles);

// This can be a class function or a regular function.
public function removeTiles (event:TimerEvent)
{
    tileTimer.stop(); // "Timer Off" in the figure below.
    // Remove the concerned tiles from the table and do whatever 
    // operations followed that in the old version of removeTiles.
}

// After a match has been found, in the old version of removeTiles,
// highlight the concerned tiles and then call
tileTimer.start(); // "Timer On" in the figure below.

The timer applied to the gem swap program:


Sequential program before the timer


Program with a Timer