Random delay for a Timer, in AS3
Hello, i would like to make a timer with a random delay in AS3.
For example, i click on a button and it trace "hello" in 2 sec. I click again and it trace "hello" in 5 sec. I click a third time, and it trace "hello" in 3 sec... etc... I tried to write this, to try to choose a delay between 2 sec and 8 sec :
var zedelais:Array = ["2000", "3000", "4000", "5000", "6000", "7000", "8000"];
var delaisok:Number = zedelais[Math.floor(Math.random()*zedelais.length)];
var zeTimer:Timer = new Timer(delaisok,1);
//var zeTimer:Timer = new Timer(5000,1);
azer.addEventListener(MouseEvent.CLICK, azergo);
function azergo(event:MouseEvent):void {
zeTimer.start();
}
zeTimer.addEventListener(TimerEvent.TIMER, timerFunction);
function timerFunction(event:TimerEvent):void{
trace("Hello world !!");
}
But it doesn't work like i want. The delay change only when the program is launch, not when i click on the button...
Any idea, please?
Thanks for your help
