PDA

View Full Version : [AS2] Random interval


Adam_C
06-29-2009, 08:44 PM
I have this code:

stop();

var rN:Number = Math.floor(Math.random(15) * 30);

setInterval(goNext,rN);

function goNext() {
gotoAndPlay(2);
}

clearInterval;


and i have placed in the enemy MC, all that happens however is that the enemies just bob up and down, any ideas?

thanks :)

P.S DOWNLOAD FROM HERE: http://uploading.com/files/6F3K6YVQ/source.zip.html

thanks again.

eddiewireless
06-29-2009, 08:54 PM
set interval woks with milliseconds, (Math.random(15) * 30) this is a very small number, so it triggers every few milliseconds....

CyanBlue
06-29-2009, 08:54 PM
You could do something like this...
//
var rN:Number = 0;
var iv:Number;

iv = setInterval(goNext, rN);

function goNext()
{
// gotoAndPlay(2);
rN = Math.floor(Math.random() * 30);
trace("rN = " + rN);
clearInterval(iv);
iv = setInterval(goNext, rN);
}
Please do post your game related question to Gaming and Game Development forum...