# Random internal mc

**URL:** <https://forum.kirupa.com/t/random-internal-mc/189842>\
**Category:** Uncategorized\
**Created:** [June 6, 2006, 4:59pm UTC](https://forum.kirupa.com/t/random-internal-mc/189842 "2006-06-06T16:59:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![qpixo](https://avatars.discourse-cdn.com/v4/letter/q/c4cdca/32.png) [@qpixo](https://forum.kirupa.com/u/qpixo)\
**Post date:** [June 6, 2006, 4:59pm UTC](https://forum.kirupa.com/t/random-internal-mc/189842/1 "2006-06-06T16:59:07Z")

</div>

does anyone know how to do a random internal movie clips NOT calling external mcs with loadmovie??

Let’s say I have two internal mc’s with instance name : my\_mc1, my\_mc2  
and I want them to load randomly in starting in frame 2

here what I did so far:

var tab\_mc = [this.my\_mc1, this.my\_mc2];

function randomMC(tab\_mc) {  
var i=tab\_mc.length;  
var r = (Math.floor(Math.random()\*i);  
return tab\_mc[r];  
}

// How can I load randomly each of them starting in frame 2?  
// gotoAndPlay() is only accept frame number or label  
onEnterFrame = function() {

}

---

<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:** [June 6, 2006, 5:15pm UTC](https://forum.kirupa.com/t/random-internal-mc/189842/2 "2006-06-06T17:15:58Z")

</div>

I’m not sure what you mean by ‘How can I load randomly each of them starting in frame 2’, but I’m assuming you want to randomly load one or the other in frame 2. If that’s the case, place this AS on frame 2:

```auto
var tab_array:Array = new Array("my_mc1","my_mc2");
var target:String = tab_array[Math.floor(Math.random()*2)];
this.attachMovie(target, target, 0);

```

---

<div class="post-metadata">

**Author:** ![qpixo](https://avatars.discourse-cdn.com/v4/letter/q/c4cdca/32.png) [@qpixo](https://forum.kirupa.com/u/qpixo)\
**Post date:** [June 6, 2006, 5:32pm UTC](https://forum.kirupa.com/t/random-internal-mc/189842/3 "2006-06-06T17:32:40Z")

</div>

thanks for your fast reply but what I mean is:

I have 2 mc’s with instance name (my\_mc1, my\_mc2). Now if u go into each of them, the sequence starts to play at frame 2 and on, I have a stop(); script in frame 1.

I want to be able to load randomly each of them in my \_root  
Is there a way to do it??

> [@Krilnon](#):
>
> I’m not sure what you mean by ‘How can I load randomly each of them starting in frame 2’, but I’m assuming you want to randomly load one or the other in frame 2. If that’s the case, place this AS on frame 2: ActionScript Code:  
> [FONT=Courier New][LEFT][COLOR=#000000] **var** [/COLOR] tab\_array:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Array[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#000000] **var** [/COLOR] [COLOR=#0000FF]target[/COLOR]:[COLOR=#0000FF]String[/COLOR] = tab\_array[COLOR=#000000][[/COLOR][COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]floor[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]][/COLOR];  
> [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]target[/COLOR], [COLOR=#0000FF]target[/COLOR], [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR];  
> [/LEFT]  
> [/FONT]

---

<div class="post-metadata">

**Author:** ![mot](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mot](https://forum.kirupa.com/u/mot)\
**Post date:** [June 6, 2006, 6:36pm UTC](https://forum.kirupa.com/t/random-internal-mc/189842/4 "2006-06-06T18:36:19Z")

</div>

What ever the function returns, when you use attachMovie just do a gotoAndPlay(2); after it.
