Althouh it that code does actually randomly select a variable from the array, it still doesnt seem to be accomplishing my task.
Im using countdown timer sourse that will countdown a set number of seconds, then do something i.e. gotoAndPlay(2);
I have set the time to countdown from 0.10 (about 4 seconds) but Im trying to make it randomly countdown from one of 4 different times, and that code you just gave me doesnt seem to do the trick.
Original Count Down Timer:
[AS]time = 0.20
function CountDownTimer(durationMin) {
AsBroadcaster.initialize(this);
this.duration = durationMin601000;
// duration in ms.
this.startTime = getTimer();
this.id = setInterval(this, “checkTime”, 1000);
this.checkTime();
}
CountDownTimer.prototype.checkTime = function() {
if (getTimer()>=this.startTime+this.duration) {
this.broadcastMessage(“onComplete”);
clearInterval(this.id);
} else {
var timeLeft = this.duration-(getTimer()-this.startTime);
this.broadcastMessage(“onProgress”, timeLeft);
}
};
// usage
// textfield used to display the timer.
createTextField(“timerTF”, 0, 0, 0, 100, 100);
// create a 15 minutes countdown timer
myTimer = new CountDownTimer(time);
myTimer.addListener(this);
// handle time progress here
function onProgress(timeLeftMS) {
var totalSeconds = timeLeftMS/1000;
var hours = Math.floor(totalSeconds/3600);
var minutes = Math.floor((totalSeconds-((hours>0) ? 3600 : 0))/60);
var seconds = Math.floor(totalSeconds-((hours3600)+(minutes60)));
if (hours<10) {
hours = “0”+hours;
}
if (minutes<10) {
minutes = “0”+minutes;
}
if (seconds<10) {
seconds = “0”+seconds;
}
timerTF.text = hours+":"+minutes+":"+seconds;
}
// handle countdown completion here
function onComplete() {
gotoAndPlay(2);
}[/AS]
Your quite right on both acounts matthewjumps. I was rather tired last night and wasnt thinking straite. I changed the variable name from “time” to “mytimer” which solved a few issues.
As for that random timearray code… it worked like a charm. Thanx again, greatly appriciated.