# A wait in action script

**URL:** <https://forum.kirupa.com/t/a-wait-in-action-script/184355>\
**Category:** Uncategorized\
**Created:** [April 4, 2006, 3:54pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355 "2006-04-04T15:54:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![johpoke](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@johpoke](https://forum.kirupa.com/u/johpoke)\
**Post date:** [April 4, 2006, 3:54pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/1 "2006-04-04T15:54:58Z")

</div>

is there a command that is in a action script which for x amount seconds the code is paused?

lets say i have a button with this code

```auto

on (release) {
    // this is done instantly
    // WAIT 5 seconds
    // this is done five seconds afterwards
}

```

Possible? if so how??

---

<div class="post-metadata">

**Author:** ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)\
**Post date:** [April 4, 2006, 3:59pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/2 "2006-04-04T15:59:18Z")

</div>

have a look at setInterval()

---

<div class="post-metadata">

**Author:** ![johpoke](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@johpoke](https://forum.kirupa.com/u/johpoke)\
**Post date:** [April 4, 2006, 4:12pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/3 "2006-04-04T16:12:27Z")

</div>

Um i searched abit on google and flash 5 help for that now but couldnt find alot, are you sure it works on flash 5?

---

<div class="post-metadata">

**Author:** ![phorte](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@phorte](https://forum.kirupa.com/u/phorte)\
**Post date:** [April 5, 2006, 12:27am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/4 "2006-04-05T00:27:07Z")

</div>

Yeah your rite about it not being suported in Flash 5:

Availability: ActionScript 1.0; Flash Player 6

I guess you could just use a getTimer, bit of a dirty way to do but it would work i guess.

[AS]on(release){  
//WHAT YOU WANT TO STRAIGHT AWAY  
time = getTimer()  
trace(“start”)

```
this.onEnterFrame = function(){
	curTime = getTimer()
	dif = curTime - time
	//trace(dif)
	if(dif &gt; 5000){
		trace("5seconds")
		delete this.onEnterFrame
		//WHAT YOU WANT IT TO DO AFTER 5 SECONDS
	}
}

```

}[/AS]

But I have a feeling this.onEnterFrame wont work cause its flash 5. So im stumped.

---

<div class="post-metadata">

**Author:** ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)\
**Post date:** [April 5, 2006, 12:30am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/5 "2006-04-05T00:30:07Z")

</div>

Oh sorry about that, I didn’t realize it wasn’t available in Flash 5 ☹

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)\
**Post date:** [April 5, 2006, 3:53am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/6 "2006-04-05T03:53:57Z")

</div>

> [@aussie devil](#):
>
> [AS]this.onEnterFrame = function(){  
> curTime = getTimer()  
> dif = curTime - time  
> //trace(dif)  
> if(dif \> 5000){  
> trace(“5seconds”)  
> delete this.onEnterFrame  
> //WHAT YOU WANT IT TO DO AFTER 5 SECONDS  
> }  
> }  
> [/AS]

That new event model (dynamic event handlers) are available since version mx only. You would have to use something like onClipEvent and getTimer instead to count the time.

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 5, 2006, 4:06am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/7 "2006-04-05T04:06:50Z")

</div>

Open a new window with the swf, when you want it to pause, close the window, and start timing with javascript, then reopen the window with a spercial argument after the time’s elapsed. :lol:

---

<div class="post-metadata">

**Author:** ![johpoke](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@johpoke](https://forum.kirupa.com/u/johpoke)\
**Post date:** [April 5, 2006, 2:47pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/8 "2006-04-05T14:47:05Z")

</div>

um nokrev i dont get that and i dont think it will work the way i want it to…

aussie devil, do you know how to do the get timer then for flash 5?  
:d:

Edit:  
and hey,

```auto

some_xes = a_number*"X";

```

How can i get this to work so that if a\_number is 5 then some\_exes is XXXXX and if a\_number is 0 then we have zero Xes, IE, it multiplies a text a with a number.

---

<div class="post-metadata">

**Author:** ![johpoke](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@johpoke](https://forum.kirupa.com/u/johpoke)\
**Post date:** [April 5, 2006, 6:05pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/9 "2006-04-05T18:05:38Z")

</div>

OK lets say i do it in flash MX, how can it be simply done…

as if its easier i will use mx instead.

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 5, 2006, 10:04pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/10 "2006-04-05T22:04:55Z")

</div>

> [@johpoke](#):
>
> um nokrev i dont get that and i dont think it will work the way i want it to…

That’s why it was wrapped in sarcasm tags… 😉

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [April 5, 2006, 11:30pm UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/11 "2006-04-05T23:30:15Z")

</div>

> That new event model (dynamic event handlers) are available since version mx only. You would have to use something like onClipEvent and getTimer instead to count the time.

onClipEvent and enterFrame events don’t work on button objects in any version of Flash.

---

<div class="post-metadata">

**Author:** ![kernel\_flash](https://avatars.discourse-cdn.com/v4/letter/k/a87d85/32.png) [@kernel\_flash](https://forum.kirupa.com/u/kernel_flash)\
**Post date:** [April 6, 2006, 7:09am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/12 "2006-04-06T07:09:19Z")

</div>

> [@johpoke](#):
>
> um nokrev i dont get that and i dont think it will work the way i want it to…
> 
> aussie devil, do you know how to do the get timer then for flash 5?  
> :d:
> 
> Edit:  
> and hey,
> 
> ```auto
> 
> some_xes = a_number*"X";
> 
> ```
> 
> How can i get this to work so that if a\_number is 5 then some\_exes is XXXXX and if a\_number is 0 then we have zero Xes, IE, it multiplies a text a with a number.

using for loop

```auto

some_xes="";
for(i=0;i<a_number;i++)
{
some_xes+="X";
}
trace(some_xes);//this'll give you a string with a_number (number) of "X"

```

---

<div class="post-metadata">

**Author:** ![phorte](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@phorte](https://forum.kirupa.com/u/phorte)\
**Post date:** [April 6, 2006, 10:47am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/13 "2006-04-06T10:47:59Z")

</div>

If you use MX, somtin like this will work: [AS]on(release){  
trace(“START CODE”)

```
codeInt = setInterval(delayFunc,5000)

function delayFunc(){
	
	trace("DELAYED CODE")
	clearInterval(codeInt)
}

```

}[/AS]

---

<div class="post-metadata">

**Author:** ![ya3](https://avatars.discourse-cdn.com/v4/letter/y/e95f7d/32.png) [@ya3](https://forum.kirupa.com/u/ya3)\
**Post date:** [April 8, 2006, 2:32am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/14 "2006-04-08T02:32:36Z")

</div>

Hmm… v5, ay?

Create a blank movie clip on the stage and call it ‘timer1’. Inside this clip, put a ‘stop();’ on the first frame, then skip forward 5 seconds (5 x your framerate), and insert a keyframe with the actions to execute after 5 secs. Then, on your button put:

on (release) {  
//thing to do instantly  
\_root.timer1.play();  
}

That’s the nice, messy AS-noob’s way 😛 (for people like me)

---

<div class="post-metadata">

**Author:** ![Macaroni\_Ted](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Macaroni\_Ted](https://forum.kirupa.com/u/Macaroni_Ted)\
**Post date:** [April 8, 2006, 4:15am UTC](https://forum.kirupa.com/t/a-wait-in-action-script/184355/15 "2006-04-08T04:15:26Z")

</div>

[quote=johpoke]um nokrev i dont get that and i dont think it will work the way i want it to…

aussie devil, do you know how to do the get timer then for flash 5?  
:d:

if you relly wanted to use getTimer() in flash 5 you could do it like this
