Array headache

Im pretty much new to arrays and its killing me to figure some stuff out. I have the following script on the main timeline in my movie

Array.prototype.shuffle=function(){
   for(i=0;i<this.length;i++){
      var tmp=this*;
      var randomNum=random(this.length);
      this*=this[randomNum];
      this[randomNum]=tmp;
   }
}



// USAGE:

arr1=["a","b","c","d","e"];
arr1.shuffle();
trace(arr1);

much thanks to sephiroth for it. Anyways, i created a movie clip with a dynamic textbox in it which i was hoping could pull one of the values from the array. How do i do this?

I uploaded the fla so hopefully one of you guys could tell me where im going wrong

once you’ve shuffled, you mean?

I believe you do something like this:

textbox.text = array[0];

I chose zero because it’s the first element of any array, but since you’ve shuffled, it shouldn’t matter what number you choose.

or… if you wanna be doubley (sp?) certain it’s random, you could use a random number as the index.

var randomNum = (Math.random() * array.length);
textbox.text = array(randomNum);

btw… I like the dragon’s blink. It’s great. :slight_smile: fyi, his ear-flap-thingy blinks out, you should fix that.

anyways… hope that helps. :slight_smile:

Im not sure i understand something. Should i put this

textbox.text = array[0];

on the movie clip itself or in the ‘var’ section of the textbox properties.

Dont mind me, i figured it out. I put the code on the movie clip itself. Thanks Daheroes and shoutouts to Sephiroth.it for the killa script!!
insert gansta pose here

no prob. :slight_smile: