# Delay function that doesn't loop

**URL:** <https://forum.kirupa.com/t/delay-function-that-doesnt-loop/219820>\
**Category:** flash\
**Created:** [March 20, 2007, 1:50pm UTC](https://forum.kirupa.com/t/delay-function-that-doesnt-loop/219820 "2007-03-20T13:50:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samurai](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Samurai](https://forum.kirupa.com/u/Samurai)\
**Post date:** [March 20, 2007, 1:50pm UTC](https://forum.kirupa.com/t/delay-function-that-doesnt-loop/219820/1 "2007-03-20T13:50:46Z")

</div>

Hey all,

```
  A couple weeks ago, I was searching for a delay function that I could put on a frame and it would hold at that frame for a given period of time.

```

I came close to finding it, but what I found used setInterval and I wasn’t able to stop it from looping.

Here is something that I am quickly starting to love, it’s not mine, but I don’t know who’s it is, it was on a piece I was working on at work (although this edition of it is partly mine, as I have adapted it to my specific needs).

hope this helps someone!

first frame

```auto

//wait function
    function wait(a) {
        stop();
        startTime = getTimer();
        this.onEnterFrame = function() {
            if (getTimer()-startTime>a) {
                delete this.onEnterFrame;
                play();
            }
        };
    }
    
    
//pause between frames
 var delay = 2000; 

```

then on the frame you want to pause or delay:

```auto

wait(delay);

```
