# Need way to delay execution

**URL:** https://forum.kirupa.com/t/need-way-to-delay-execution/62608
**Category:** Uncategorized
**Created:** [August 29, 2004, 9:49pm UTC](https://forum.kirupa.com/t/need-way-to-delay-execution/62608 "2004-08-29T21:49:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![acor](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@acor](https://forum.kirupa.com/u/acor)
#### Post date: [August 29, 2004, 9:49pm UTC](https://forum.kirupa.com/t/need-way-to-delay-execution/62608/1 "2004-08-29T21:49:09Z")

</div>

I just need a simple way for flash to delay the execution of a group of actions for a few seconds.

Here is the code I need delayed:

\_root.randomnumber=(random(20))

if (\_root.randomnumber\<=8){\_root.commentbox=“Hit!”}

if (\_root.randomnumber\<=8){\_root.enemyhp-=15, nextFrame()  
}

else {\_root.commentbox=“Miss!”  
}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 29, 2004, 10:36pm UTC](https://forum.kirupa.com/t/need-way-to-delay-execution/62608/2 "2004-08-29T22:36:41Z")

</div>

just make a mvc to the left of your stage… you know you will make it 12 frames long and on the last key frame put an add AS:  
\_root.num += 1  
and then on that movie clip put the:  
onClipEvent(EnterFrame) {  
if (\_root.num == 12) {  
goto and play(number)  
}  
}  
Note: thats a rough example dont copy the code.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 29, 2004, 10:44pm UTC](https://forum.kirupa.com/t/need-way-to-delay-execution/62608/3 "2004-08-29T22:44:35Z")

</div>

i cant do that becuase I need to acess code outside of the movie clip and I dont think that will work… Unless I’m meiss understanding what you are saying

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 29, 2004, 10:51pm UTC](https://forum.kirupa.com/t/need-way-to-delay-execution/62608/4 "2004-08-29T22:51:23Z")

</div>

it doesnt matter its used more for multiple waiting times that takes like no space up

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 29, 2004, 11:10pm UTC](https://forum.kirupa.com/t/need-way-to-delay-execution/62608/5 "2004-08-29T23:10:44Z")

</div>

or simply wrap the code you want delayed with this:

```auto
waitV=setInterval(function(){
    clearInterval(waitV)
    ...
    the code you want delayed
    ...
},x) //where x is the number of milliseconds you want it delayed for

```

ill wrap it around your code so you can see what i mean and ill make it wait for 5 secs:

```auto
waitV=setInterval(function(){
    clearInterval(waitV)
    _root.randomnumber=(random(20))
    if (_root.randomnumber<=8){_root.commentbox="Hit!"}
    if (_root.randomnumber<=8){_root.enemyhp-=15, nextFrame()
    }
    else {_root.commentbox="Miss!"
    }
},5000)

```

Prophet.
