[AS3]Random do something without repeat
Hi,
I've 3 movieclip on stage which is mc1,mc2,mc3
at first they are alpha=0
What I want is when i click on revealBtn, 1 of them will show up as alpha=1.
But with my code below, sometimes I need to click about 5 times or more only can make all those mc show up.
Is there any solution for what I wanted?
Quote:
var mcArray:Array = [mc1,mc2,mc3];
for (var j:int = 0; j < mcArray.length; j++)
{
mcArray[j].alpha = 0;
}
revealBtn.buttonMode = true;
revealBtn.useHandCursor = false;
revealBtn.addEventListener(MouseEvent.CLICK, revealClick);
function revealClick(event:MouseEvent):void
{
//Generate random number (integer) between 0 and mcArray.length
var i:Number = Math.floor(Math.random() * mcArray.length);
//Select ith element of mcArray
var movieClipToEdit:MovieClip = mcArray[i] as MovieClip;
//Change its alpha to 1
movieClipToEdit.alpha = 1;
}