# Random

**URL:** <https://forum.kirupa.com/t/random/27851>\
**Category:** Uncategorized\
**Created:** [August 7, 2003, 6:46am UTC](https://forum.kirupa.com/t/random/27851 "2003-08-07T06:46:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![mystee](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mystee](https://forum.kirupa.com/u/mystee)\
**Post date:** [August 7, 2003, 6:46am UTC](https://forum.kirupa.com/t/random/27851/1 "2003-08-07T06:46:23Z")

</div>

How can i make my flash animation such that…it will load randomly…random in the sense that it will load at different labels of the animation whenever its loaded…

help!! ☹

---

<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 7, 2003, 7:02am UTC](https://forum.kirupa.com/t/random/27851/2 "2003-08-07T07:02:44Z")

</div>

> \*Originally posted by mystee \*  
> \*\*random in the sense that it will load at different labels of the animation whenever its loaded…  
> \*\*

What do you mean? :-\ can you be more specific?

---

<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 7, 2003, 7:08am UTC](https://forum.kirupa.com/t/random/27851/3 "2003-08-07T07:08:48Z")

</div>

for example i have 3 labels…under each of them…there is an image…so it means there are 3 images in the clip…

How can i randomise the image whenever the animation is loaded? eg: sometimes it will load image1 first, sometimes it will load image2 first…so on…

---

<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 7, 2003, 7:11am UTC](https://forum.kirupa.com/t/random/27851/4 "2003-08-07T07:11:01Z")

</div>

You could store the labels in an Array object, and pull out a random label. 🙂  
[AS]var labels = [“label1”, “label2”, “label3”, “label4”, “etc”];  
var frame = labels[Math.floor(Math.random()\*labels.length)];  
myMovieClip.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:** [August 7, 2003, 7:13am UTC](https://forum.kirupa.com/t/random/27851/5 "2003-08-07T07:13:34Z")

</div>

wow…i don’t understand your script…can explain?

actually…for my case…its not image under the label…its actually an animation…so it means…under each label…there’s diff animation playing…

---

<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 7, 2003, 7:20am UTC](https://forum.kirupa.com/t/random/27851/6 "2003-08-07T07:20:28Z")

</div>

Uhmm…  
[AS]// frames label (no problem here, right?)  
var labels = [“label1”, “label2”, “label3”, “label4”, “etc”];  
/\* since arrays are zero based  
we need a random number between 0 and the array length minus 1  
Math.floor takes care of that \*/  
var frame = labels[Math.floor(Math.random()\*labels.length)];  
// send playhead of that movieclip to the random frame  
myMovieClip.gotoAndStop(frame);[/AS]  
Does that help at all? I’m not very good at explaining how things work… 😛

---

<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 7, 2003, 7:26am UTC](https://forum.kirupa.com/t/random/27851/7 "2003-08-07T07:26:46Z")

</div>

what’s math.floor? i’m still new to all this you see…=|

---

<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 7, 2003, 7:29am UTC](https://forum.kirupa.com/t/random/27851/8 "2003-08-07T07:29:20Z")

</div>

seems like there’s no random animation…

---

<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 7, 2003, 7:37am UTC](https://forum.kirupa.com/t/random/27851/9 "2003-08-07T07:37:34Z")

</div>

> _Originally posted by mystee_  
> **what’s math.floor? i’m still new to all this you see…=|**

[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary456.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary456.html)

> _Originally posted by mystee_  
> **seems like there’s no random animation…**

Did you replace label1, label2, label3, etc. with the actual frame labels in the MovieClip?

---

<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 7, 2003, 7:42am UTC](https://forum.kirupa.com/t/random/27851/10 "2003-08-07T07:42:36Z")

</div>

yah…i did…no difference…no random…hmm…

---

<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 7, 2003, 7:47am UTC](https://forum.kirupa.com/t/random/27851/11 "2003-08-07T07:47:00Z")

</div>

Can you attach the FLA?

---

<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 7, 2003, 7:50am UTC](https://forum.kirupa.com/t/random/27851/12 "2003-08-07T07:50:06Z")

</div>

unfortuntely…the size doesn’tallow me to…can u show me with an example of yours?

---

<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 7, 2003, 8:00am UTC](https://forum.kirupa.com/t/random/27851/13 "2003-08-07T08:00:46Z")

</div>

Done. 😉

---

<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 7, 2003, 8:20am UTC](https://forum.kirupa.com/t/random/27851/14 "2003-08-07T08:20:41Z")

</div>

Thanks…it’s close to what i want…

but for my case…under each label…there’s a MC…and somehow with this script…it cannot work…=(

What could be the problem here? hmm…

---

<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 7, 2003, 8:27am UTC](https://forum.kirupa.com/t/random/27851/15 "2003-08-07T08:27:23Z")

</div>

Could you send me the FLA to my email? I just sent you a PM with my address.

---

<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 7, 2003, 9:14am UTC](https://forum.kirupa.com/t/random/27851/16 "2003-08-07T09:14:14Z")

</div>

its ok! I managed to spot my mistake! THANKS ALOT!!! 🙂

---

<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 7, 2003, 5:21pm UTC](https://forum.kirupa.com/t/random/27851/17 "2003-08-07T17:21:46Z")

</div>

You’re welcome. =)

I’m curious though… what was the problem? 😛
