Random Array Elements In Dynamic Text Box
Hi,
I have an array (named arrayFull), and I want my dynamic text box (named messageText) to display one random element from the array, changing once per second.
The code I have makes it display all elements of the array at once in random order, changing once per second.
How do I make it display just one element from the array at any given time?
This is the code:
var arrayFull:Array = new Array(1,2,3,4,5);
import flash.utils.Timer;
import flash.events.TimerEvent;
var myTimer:Timer = new Timer(1000, (arrayFull.length));
myTimer.addEventListener(TimerEvent.TIMER, runOnce);
myTimer.start();
function runOnce(e:TimerEvent):void {
messageText.htmlText="";
updateText ();
}
var maximumMessages:Number = 1;
var currentMessages:Number = 0;
function updateText(){
for (var i = currentMessages; i<maximumMessages; i++) {
messageText.htmlText += arrayFull.sort(function () {
return Math.random() ? true : false;
});
for (i = 0; i < 4; i++) {
this[i].text = arrayFull[i];
}
}
}
Thank you for your help.