10 buttons, only 1 visible

Okay, ive got another problem… i have 10 buttons (b1,…,b10) and want to set their default visible property to false. I want only 1 of those mcs (pick by random) to be visible. How i do that?
Thanks

button.prototype._visible = false

rand = Math.round(Math.random()*10)
this[“b”+rand]._visible = true

that i think does it

No Ahmed, didnt work…

If ahmed’s way didn’t work, then probably your Buttons are behaving as Movieclips, try this instead:

MovieClip.prototype._visible = false
this["b"+(Math.floor(Math.random()*10)+1)]._visible = true

Ahmeds way should work, you just have to make sure your button instance name is b1, b2, b3, etc.

Didnt work. Ive tried both ways.
My buttons are not behaving as movie clips.
I have 10 buttons on stage (b1,…,b10) and placed the code on 1st frame of my timeline.
All buttons were still visible.

Well this script is assuming you set all your buttons as invisible first.

Example…
[AS]//cycle through buttons to make them all invisible
for (var i = 1; i<=10; i++) {
this[“b”+i]._visible = false;
}
//choose random number from 1 to 10
var rand = Math.floor(Math.random()*10+1);
//make 1 button visible again
this[“b”+rand]._visible = true;[/AS]

And a slight variation…

[AS]//choose random number from 1 to 10
var rand = Math.floor(Math.random()*10+1);
//button which will stay visible
var keepVisible = this[“b”+rand];
//cycle through buttons to make them all invisible
for (var i = 1; i<=10; i++) {
//if current button is not the keepVisible button
if (this[“b”+i] != keepVisible) {
//make it invisible
this[“b”+i]._visible = false;
} else {
//else keep it visible
this[“b”+rand]._visible = true;
}
}[/AS]

NOTE: You can remove the [AS] else {
//else keep it visible
this[“b”+rand]._visible = true;
}[/AS] and it will still work exactly the same, I just felt it was easier to explain with it in there.