views:

97

answers:

0

Hi,

I have the following function:

function update(e:Event):void
{
var val:Number = Math.random() * 120;
rgb.r.x = rgb.r.y = val;
rgb.b.x = rgb.b.y = -val;
}

And im looping it with:

stage.addEventListener(Event.ENTER_FRAME, update);

But what I need to do would be something like:

Random number between 1 and 20
If the number is > 10
Call function Update
and keep caling it for 20 seconds
else
do nothing for 10 seconds
Repeat this block of code forever

Can someone help me write this please?

Best I could come up with:

var myTimer:Timer = new Timer(2000);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener (e:TimerEvent):void{
trace("Timer is Triggered");
var val1:Number = Math.random() * 30;
trace(val1);
if (val1 > 18){
stage.removeEventListener(Event.ENTER_FRAME, nothing);
stage.addEventListener(Event.ENTER_FRAME, update);

}else{
stage.removeEventListener(Event.ENTER_FRAME, update);
stage.addEventListener(Event.ENTER_FRAME, nothing);
}
}
myTimer.start();