# Please, Help me... Random play for movieclip

**URL:** https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603
**Category:** flash
**Created:** [May 23, 2003, 5:19pm UTC](https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603 "2003-05-23T17:19:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![koamis](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@koamis](https://forum.kirupa.com/u/koamis)
#### Post date: [May 23, 2003, 5:19pm UTC](https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603/1 "2003-05-23T17:19:24Z")

</div>

Hi, I need help for this,

how can play a MovieClip in a random delay or at random time in my main scene? need an actionscript? anybody can help me?

in advance, thankful

koamis :tb:

---

<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 23, 2003, 5:41pm UTC](https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603/2 "2003-05-23T17:41:49Z")

</div>

Hi,  
Put this code in frame1 of your mc  
[AS]stop();  
random\_number = random(1500)+1000;  
delay = setInterval(this, “play”, random\_number);  
//and in the last frame  
clearInterval(delay);  
gotoAndPlay(1);  
[/AS]  
Alter the number in the brackets to change the “randomness”

Hope that helps

SteveD

---

<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 26, 2003, 6:19pm UTC](https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603/3 "2003-05-26T18:19:01Z")

</div>

Thanks SteveD, especially for your promptitude

I put the code in frame 1 and set (10500)+1000 but it continue at constant play, my MC have 450 frames, can affect this?

again, 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 27, 2003, 5:41am UTC](https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603/4 "2003-05-27T05:41:15Z")

</div>

Hi,  
Apologies, change the number outside the bracket, that will give you more of a delay.  
The code will only delay in frame 1, once the playhead leaves fr1 it will play normally.  
You can do on of two things (if you want to change this)  
alter :  
[AS]delay = setInterval(this, “play”, random\_number);  
//to  
delay = setInterval(this, “nextFrame”, random\_number);[/AS]

this will advance the plyahead one frame at a time and invoke delay() in every frame, alternatively if you want the the animation to stop at certain points, leave the code as is and put:  
[AS]stop()  
delay();[/AS]  
at different key frames along the 450 frames

Hope that helps

SteveD

---

<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: [June 9, 2003, 4:41pm UTC](https://forum.kirupa.com/t/please-help-me-random-play-for-movieclip/21603/5 "2003-06-09T16:41:12Z")

</div>

Hey, this script work for me…

## ActionScript:

stop();  
random\_number = Math.ceil(Math.random()\*5000);  
delay = setInterval(this, “play”, random\_number);

* * *

thanks for the enlightenment
