-
[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?
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;
}
-
Senior Member
Then it would not be random any more. What you need to do is to select the first button randomly and then deleting the button id from the array. Now the array contains only the two remaining buttons and next time one of those will be selected until only one button is left.
- The right of the People to create Flash movies shall not be infringed. -
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|