# Play random movie array without repeat

**URL:** <https://forum.kirupa.com/t/play-random-movie-array-without-repeat/332413>\
**Category:** Uncategorized\
**Created:** [May 30, 2014, 2:20pm UTC](https://forum.kirupa.com/t/play-random-movie-array-without-repeat/332413 "2014-05-30T14:20:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdcsurf](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tdcsurf](https://forum.kirupa.com/u/tdcsurf)\
**Post date:** [May 30, 2014, 2:20pm UTC](https://forum.kirupa.com/t/play-random-movie-array-without-repeat/332413/1 "2014-05-30T14:20:32Z")

</div>

I’m trying to help out a friend and apparently, I cant. :-/  
There is 3 movie clips and 1 intro movie. At the end of each movie there is a function to call the root function

```php
MovieClip(root).addFrameScript(626, 2);

```

This is the code on the root in frame 1

```php
stop ();
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;

/*trace("Frame 1");*/

var movieArray:Array = new Array();

movieArray = ["PersonMc1","PersonMc2","PersonMc3"];

var MovieClipContainer:Sprite=new Sprite();
var IntroMc1:IntroMc=new IntroMc();
var PersonMc1:Person1Mc=new Person1Mc();
var PersonMc2:Person2Mc=new Person2Mc();
var PersonMc3:Person3Mc=new Person3Mc();

addChild (MovieClipContainer);

MovieClipContainer.addChild (IntroMc1);
MovieClipContainer.addChild (PersonMc1);
MovieClipContainer.addChild (PersonMc2);
MovieClipContainer.addChild (PersonMc3);

PersonMc1.visible = false;
PersonMc2.visible = false;
PersonMc3.visible = false;

PersonMc1.stop ();
PersonMc2.stop ();
PersonMc3.stop ();

```

and this is the code on frame 2

```php
stop ();

var prevIndex:int;
clickStart ();

function clickStart () {

    if ((MovieClip(root).movieArray[Math.floor(Math.random() * 3)]) == "PersonMc1") {

        if (MovieClip(root).movieArray == PersonMc1) {

            clickStart ();

        } else {

            MovieClip(root).PersonMc1.visible = true;
            MovieClip(root).PersonMc1.gotoAndPlay (1);
            prevIndex = MovieClip(root).MovieClipContainer.getChildIndex(PersonMc1);

            MovieClip(root).MovieClipContainer.setChildIndex (PersonMc1,MovieClip(root).MovieClipContainer.numChildren-1);
            trace (prevIndex);
            trace (MovieClip(root).MovieClipContainer.numChildren-1);
        }

    } else if ((MovieClip(root).movieArray[Math.floor(Math.random() * 3)]) == "PersonMc2") {
        if (MovieClip(root).movieArray == PersonMc2) {
            clickStart ();

        } else {
            MovieClip(root).PersonMc2.visible = true;
            MovieClip(root).PersonMc2.gotoAndPlay (1);
            prevIndex = MovieClip(root).MovieClipContainer.getChildIndex(PersonMc2);

            MovieClip(root).MovieClipContainer.setChildIndex (PersonMc2,MovieClip(root).MovieClipContainer.numChildren-1);
            trace (prevIndex);

        }

    } else if ((MovieClip(root).movieArray[Math.floor(Math.random() * 3)]) == "PersonMc3") {
        if (MovieClip(root).movieArray == PersonMc3) {
            clickStart ();

        } else {
            MovieClip(root).PersonMc3.visible = true;
            MovieClip(root).PersonMc3.gotoAndPlay (1);
            prevIndex = MovieClip(root).MovieClipContainer.getChildIndex(PersonMc3);

            MovieClip(root).MovieClipContainer.setChildIndex (PersonMc3,MovieClip(root).MovieClipContainer.numChildren-1);
            trace (prevIndex);

        }

    }

}

```

There seems to be a lot of repeat code doing the same thing but I cant get it to work. There needs to be a way to create a random list and play that list without a repeat. The issue is, the current movie needs to animate OVER the previous movie but if the same movie animates twice, it is blank underneath and looks like a glitch.

I thought I could figure out an easy solution, but I’m just not all that good with AS3 as I aspire to.

Thanks very much for your time, I really appreciate it!
