# Trying to implement a timer

**URL:** <https://forum.kirupa.com/t/trying-to-implement-a-timer/258589>\
**Category:** flash\
**Created:** [April 25, 2008, 1:42pm UTC](https://forum.kirupa.com/t/trying-to-implement-a-timer/258589 "2008-04-25T13:42:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulcybulski](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@paulcybulski](https://forum.kirupa.com/u/paulcybulski)\
**Post date:** [April 25, 2008, 1:42pm UTC](https://forum.kirupa.com/t/trying-to-implement-a-timer/258589/1 "2008-04-25T13:42:27Z")

</div>

I have a search field that searches on key press…so you type b and it will automatically return all the words that start with b…if you type ba it will return all the words that start with ba…and so on and so forth…what I want to do is put a delay of one or two seconds before the search actually starts after the user STOPS typing…because with large lists I am experiencing lag…so I want the search to start once the person stops typing…here is what I have…

```auto

keyListener.onKeyUp = function() 
{
    clearInterval(counter);
    if(showLoad)
    {
        trace("....1");
        var seconds = 2;
        function Timer() 
        {
            trace("....2");
            seconds -= 1;
            trace(seconds);
            if (seconds==0) 
            {
                trace("....3");
                if(Key.getCode() != 38 && Key.getCode() != 40)
                {
                    trace("....4");
                                        //perform search function....
                }
            }
        }
        counter = setInterval(Timer, 1000);
    }
}

```

the output trace is only the first one “…1”

Any ideas?
