# 10 buttons, only 1 visible

**URL:** https://forum.kirupa.com/t/10-buttons-only-1-visible/24902
**Category:** flash
**Created:** [July 7, 2003, 12:42am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902 "2003-07-07T00:42:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![up11](https://avatars.discourse-cdn.com/v4/letter/u/dc4da7/32.png) [@up11](https://forum.kirupa.com/u/up11)
#### Post date: [July 7, 2003, 12:42am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/1 "2003-07-07T00:42:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 12:48am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/2 "2003-07-07T00:48:21Z")

</div>

button.prototype.\_visible = false

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

that i think does it

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 12:52am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/3 "2003-07-07T00:52:04Z")

</div>

No Ahmed, didnt work…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 1:00am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/4 "2003-07-07T01:00:07Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 1:03am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/5 "2003-07-07T01:03:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 1:09am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/6 "2003-07-07T01:09:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 3:47am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/7 "2003-07-07T03:47:27Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2003, 3:52am UTC](https://forum.kirupa.com/t/10-buttons-only-1-visible/24902/8 "2003-07-07T03:52:04Z")

</div>

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.
