Как указано получить случайное число в диапазоне от 0 до 9, Math.random это путь:
var n:int = Math.floor(Math.Random()*10);
Но для решения второго вопроса, как получить его, чтобы он делает это каждую миллисекунду
import flash.utils.setInterval;
import flash.utils.clearInterval;
//variable for the intervalID,
//and the variable that will be assigned the random number
var rnGenIID:uint, rn:int;
//function to update the rn variable
//to the newly generated random number
function updateRN():void{
rn = random0to9();
//as suggested, you could just use:
//rn = int(Math.random()*10);
//but I figured you might find having it as a function kind of useful,
//...
//the trace is here to show you the newly updated variable
trace(rn);
}
function random0to9():int{
//in AS3, when you type a function as an int or a uint,
//so instead of using:
//return Math.floor(Math.random()*10);
//or
//return int(Math.random()*10);
//we use:
return Math.random()*10;
}
//doing this assigns rnGenIID a number representing the interval's ID#
//and it set it up so that the function updateRN will be called every 1 ms
rnGenIID = setInterval(updateRN,1);
//to clear the interval
//clearInterval(rnGenIID);
Почему вы используете 'setInterval' вместо рекурсивного' Timer' след? –
@Matt McDonald, 'setTimeout' /' setInterval' являются более легкими, чем 'Timer', поскольку это языковая конструкция. Если вы знаете, что вы делаете с ними, они могут творить чудеса. Чтобы помочь новичку со вспышкой, я бы предложил «Таймер». – zzzzBov
Ну, я отвечу на вопрос? имеет значение, в какой порядок входит случайное число? если нет, я избегаю класса Timer. Я также пытался облегчить его и других людей, просматривающих это, что может быть использовано для javascript. –