# Random playback of animation

**URL:** <https://forum.kirupa.com/t/random-playback-of-animation/26420>\
**Category:** Uncategorized\
**Created:** [July 22, 2003, 11:46pm UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420 "2003-07-22T23:46:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spence](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@spence](https://forum.kirupa.com/u/spence)\
**Post date:** [July 22, 2003, 11:46pm UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420/1 "2003-07-22T23:46:27Z")

</div>

Hi,

Ok I’ve seen the math.random function and realize that it’s great for generating random numbers…

But there must be a way of then assigning the number to a frame etc

I basically (although I know this is anything but basic) want to creat a movie clip that when the mouse goes over it a random animation plays ie a random frame etc

Is this possible? Im sure it must be!! it’s just well out of the realms of my limited actionscripting knowledge (which isn’t alot!!)

Thanks for any help:-\

Spence

---

<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:** [July 23, 2003, 12:27am UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420/2 "2003-07-23T00:27:58Z")

</div>

You can use this code on your movie clip:[AS]on (rollOver) {  
frame = Math.floor(Math.random()\*this.\_totalframes)+1;  
this.gotoAndStop(frame);  
}[/AS]

---

<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:** [July 23, 2003, 12:29am UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420/3 "2003-07-23T00:29:28Z")

</div>

```php

on(rollOver){
_root.mcWithAnimations.gotoAndStop (Math.random(#ofFrames)+1)
}

```

put a button on your stage and put this action on it  
then create another movieclip with all your animations on keyframes in the movieclip  
so when this script is activated it will pick a random number from 0 to whatever number you put and then add 1 to it since you don’t have a 0 frame number. so in that box put the number of frames in your movieclip  
then when it goes to that frame and stop it will activate your lil clip and play it’s animation

i hope this helps

------ edit -------  
claudio you beat me to it … you can use his script … it will work better … good luck

---

<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:** [July 23, 2003, 12:47am UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420/4 "2003-07-23T00:47:19Z")

</div>

```auto
on(rollOver){
_root.mcWithAnimations.gotoAndStop(random(totalFrames)+1));
}

```

:beam:

---

<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:** [July 23, 2003, 6:57am UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420/5 "2003-07-23T06:57:03Z")

</div>

Thanks guys I’ll try these various codes tonight:beam:

Spence

---

<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:** [July 23, 2003, 7:19am UTC](https://forum.kirupa.com/t/random-playback-of-animation/26420/6 "2003-07-23T07:19:25Z")

</div>

You’re welcome 🙂
