# Gotoand play random frame

**URL:** <https://forum.kirupa.com/t/gotoand-play-random-frame/246047>\
**Category:** Uncategorized\
**Created:** [December 6, 2007, 4:32pm UTC](https://forum.kirupa.com/t/gotoand-play-random-frame/246047 "2007-12-06T16:32:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pr1](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@pr1](https://forum.kirupa.com/u/pr1)\
**Post date:** [December 6, 2007, 4:32pm UTC](https://forum.kirupa.com/t/gotoand-play-random-frame/246047/1 "2007-12-06T16:32:30Z")

</div>

Hello,

In my flash piece I’ve created the follow code in the first frame of the action script layer:

```php
function getRandomLabel():String {
  var labels:Array = new Array("2", "4", "3");
  var index:Number = Math.floor(Math.random() * labels.length);
  return labels[index];
}
this.gotoAndPlay(getRandomLabel());

```

This code is not working properly. It loads frames outside of the array.

My frame labels consist of the frame names 2 3 4
