lundi 2 mars 2015

AS3 - random value in 9 different dinamic text with array

please help me with a little project. I have 9 different dinamic text with 9 default value. What i need! When i press 'enter' must random chose and display only one single value. like a roulete or slot machine. initial value must be on the same place but only one to be display.


On second press keyboard (enter) it must change and display initial value. and loop of that


right now i made a code to change value on value1.text (chose random from array)





function randomJob(){
var jobs:Array = new Array("apple", "lemon", "banana", "orange", "mandarin", "lime", "kiwi", "pear", "apricot");
value1.text = jobs[randomNumber(jobs.length-1)];
}

function randomNumber(max){
return(Math.round(Math.random()*max));
}

this.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
function keyDownHandler(event : KeyboardEvent) : void
{
if (event.keyCode == Keyboard.ENTER)
{
randomJob();
}
}



example: preview





Aucun commentaire:

Enregistrer un commentaire