# How to create a time delay prototype script

**URL:** <https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635>\
**Category:** Uncategorized\
**Created:** [May 29, 2004, 4:49am UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635 "2004-05-29T04:49:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![julietling](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@julietling](https://forum.kirupa.com/u/julietling)\
**Post date:** [May 29, 2004, 4:49am UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635/1 "2004-05-29T04:49:33Z")

</div>

problem:  
how to create a time delay prototype script.

situation:  
click on buttons to run a display mc1 after 2 sec delay

//script on button//  
on (press) {  
\_root.mc1.wait();  
}

script needed:

MovieClip.prototype.wait = function() {  
\_root.mc1.gotoAndPlay(2);  
this.clearInterval(this.setInterval(wait, 2000));  
}

thanks

---

<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:** [May 29, 2004, 4:53am UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635/2 "2004-05-29T04:53:28Z")

</div>

function wait(){  
\_root.mc1.gotoAndPlay(2);  
clearInterval(IDName)  
}

on button:  
on (press) {  
IDName=setInterval(wait, 2000);  
}

Adam

---

<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:** [May 29, 2004, 3:10pm UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635/3 "2004-05-29T15:10:14Z")

</div>

thanks, adam

i’m freakin new to actionscript, i hv no idea what is the code i wrote in my question 🙂

---

<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:** [May 29, 2004, 4:28pm UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635/4 "2004-05-29T16:28:30Z")

</div>

sorry for not being clear, i actually need to target the  
gotoAndPlay(2) to many MCs. I wanted on press of a button, the MC (say, clipA) indicated on the event handler of the button invoke moving the playhead to frame 2 inside clipA  
and so on…

//button 1//  
on (press) {  
\_root.clipA.wait();  
}

//button 2//  
on (press) {  
\_root.clipB.wait();  
}

//button 3//  
on (press) {  
\_root.clipC.wait();  
}

and so on…

thanks

---

<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:** [May 29, 2004, 4:38pm UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635/5 "2004-05-29T16:38:45Z")

</div>

You could assign variables to each button such as"

on the button that plays clipA

on (press) {  
clipName="A"  
IDName=setInterval(wait, 2000);  
}

and the button that plays clipB

on (press) {  
clipName="B"  
IDName=setInterval(wait, 2000);  
}

And then you could set your function up and use this variable clipName in it to target the clip you want to play:

function wait(){  
\_root[“clip”+clipName].gotoAndPlay(2);//clipName will return A or B  
clearInterval(IDName)  
}

should work for ya 😉

Adam

---

<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:** [May 30, 2004, 2:06am UTC](https://forum.kirupa.com/t/how-to-create-a-time-delay-prototype-script/111635/6 "2004-05-30T02:06:39Z")

</div>

how do i change the script to work if the function is on the main timeline while the button is in another mc,  
since the on (press) can’t find the function inside the mc?
