# Not playing the same 2 random frame lables in a row

**URL:** <https://forum.kirupa.com/t/not-playing-the-same-2-random-frame-lables-in-a-row/286072>\
**Category:** Uncategorized\
**Created:** [April 9, 2009, 3:57pm UTC](https://forum.kirupa.com/t/not-playing-the-same-2-random-frame-lables-in-a-row/286072 "2009-04-09T15:57:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnyct9760](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@johnyct9760](https://forum.kirupa.com/u/johnyct9760)\
**Post date:** [April 9, 2009, 3:57pm UTC](https://forum.kirupa.com/t/not-playing-the-same-2-random-frame-lables-in-a-row/286072/1 "2009-04-09T15:57:24Z")

</div>

Hi everyone last time I left you I was working on having a slide show that jumps to random frames labels well I got that taken care off:

```php

function getRandomLabel():String
{
    var labels:Array = new Array("a","b","c");
    var index:Number = Math.floor(Math.random() * labels.length);
    return labels[index];
}
this.gotoAndPlay(getRandomLabel()); 

```

But the plot thickens, now I’m trying to get the abvoid playing the same frame lable 2 times in a row. Here is the code I currently have:

```php

var labels:Array = new Array("a","b","c","d","e","f");
var index:Number = Math.floor(Math.random() * labels.length);
var currentRandomLabel:String;
var newRandomLabel:String;
function getRandomLabel():String
{
 return labels[index];
}
function nextRandomFrame():void
{
 getRandomLabel();
 trace("Current random label: " + currentRandomLabel);
 if(currentRandomLabel != newRandomLabel)
 {
   currentRandomLabel = newRandomLabel;
   trace("New Random Label: " + newRandomLabel);
   this.gotoAndPlay(getRandomLabel());
 }
 else
 {
   trace("I'm trying to find a new frame label!");
   nextRandomFrame();
 }
}

```

Now I’m looking this code over and to me it looks like it should be working. I simply have added a

```php

var currentRandomLabel:String;
var newRandomLabel:String;

```

To the code and then compair them in a conditonal. What is actully happening is when I publish my movie it simply plays throught the time line linearly going from A to F in normal order.  
If any one feels like looking over the FLA plz feel free to DL it at this link:  
[http://www.johncliffordtaylor.com/test/random\_frame.fla](http://www.johncliffordtaylor.com/test/random_frame.fla)  
or  
[http://www.johncliffordtaylor.com/test/random\_frame.rar](http://www.johncliffordtaylor.com/test/random_frame.rar)  
Thank you for all your help  
JT
