# Special button function?

**URL:** https://forum.kirupa.com/t/special-button-function/260122
**Category:** Uncategorized
**Created:** [May 12, 2008, 7:33pm UTC](https://forum.kirupa.com/t/special-button-function/260122 "2008-05-12T19:33:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![newsteve](https://avatars.discourse-cdn.com/v4/letter/n/5f8ce5/32.png) [@newsteve](https://forum.kirupa.com/u/newsteve)
#### Post date: [May 12, 2008, 7:33pm UTC](https://forum.kirupa.com/t/special-button-function/260122/1 "2008-05-12T19:33:25Z")

</div>

hello,

i am creating a series of navigational menus in flash, all linked to each other. when the user presses a button on one menu, another pops up but the original menu also stays on screen. On the original menu, I would like all of the non-pressed buttons’ alpha to degrade by half. I realize that I can just specify which specific buttons’ alpha I would like to degrade within the onRelease function of the button, but this could get cumbersome over many menus and buttons. Is there a function that can be written which would degrade the alpha of all buttons EXCEPT for the one that was just pressed?

Thanks for any help.

PS Im using AS 2 for this.

---

<div class="post-metadata">

### Author: ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)
#### Post date: [May 13, 2008, 10:20am UTC](https://forum.kirupa.com/t/special-button-function/260122/2 "2008-05-13T10:20:23Z")

</div>

// assuming that your movieclips are called btn1,btn2,btn3…btn6  
// and you want to change the alpha of all other to 40% except the selected one

for(var i=1;i\<=6;i++)  
{  
var mc:MovieClip=this[“btn”+i];  
mc.id=i;  
mc.onRollOver=rollIn;  
mc.onRollOut=reset;  
}

function rollIn()  
{  
fadeAllBut(this.id);  
}

function reset()  
{  
for(var i=1;i\<=6;i++)  
{  
var mc:MovieClip=this[“btn”+i];  
mc.\_alpha=100;  
}

}

function fadeAllBut(id)  
{  
for(var i=1;i\<=6;i++)  
{  
var mc:MovieClip=this[“btn”+i];  
if(i!=id)  
{  
mc.\_alpha=40;  
}  
}  
}

// please let me know if you have any problems with this

---

<div class="post-metadata">

### Author: ![newsteve](https://avatars.discourse-cdn.com/v4/letter/n/5f8ce5/32.png) [@newsteve](https://forum.kirupa.com/u/newsteve)
#### Post date: [May 21, 2008, 3:52pm UTC](https://forum.kirupa.com/t/special-button-function/260122/3 "2008-05-21T15:52:07Z")

</div>

I just got back to this problem,

Thanks for your help. The code below worked. However,

I was wondering if you (or anyone) knew how I could put all of this into a function which will work when I rollover the desired button. The problem is that I also want other things to happen, specific to each button, when you rollover them. For example when I put this code:

btn1.onRelease = function(){  
gotoAndPlay(2);  
}

the movie will move to frame 2 but it will ignore the code for the fading buttons, and Im not sure why…?

Any help would be great, thanks.

[quote=sparkdemon;2325472]// assuming that your movieclips are called btn1,btn2,btn3…btn6  
// and you want to change the alpha of all other to 40% except the selected one

for(var i=1;i\<=6;i++)  
{  
var mc:MovieClip=this[“btn”+i];  
mc.id=i;  
mc.onRollOver=rollIn;  
mc.onRollOut=reset;  
}

function rollIn()  
{  
fadeAllBut(this.id);  
}

function reset()  
{  
for(var i=1;i\<=6;i++)  
{  
var mc:MovieClip=this[“btn”+i];  
mc.\_alpha=100;  
}

}

function fadeAllBut(id)  
{  
for(var i=1;i\<=6;i++)  
{  
var mc:MovieClip=this[“btn”+i];  
if(i!=id)  
{  
mc.\_alpha=40;  
}  
}  
}

// please let me know if you have any problems with this[/quote]

---

<div class="post-metadata">

### Author: ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)
#### Post date: [May 21, 2008, 3:59pm UTC](https://forum.kirupa.com/t/special-button-function/260122/4 "2008-05-21T15:59:24Z")

</div>

timeline is \*\*\*\* and \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* to make a point

you shouldn’t be trying to move around the timeline with even basic AS

you will need to make pages \_visible = false and \_visible = true

with the same priniple as the button code

…

plus it is in a function… two plus

---

<div class="post-metadata">

### Author: ![newsteve](https://avatars.discourse-cdn.com/v4/letter/n/5f8ce5/32.png) [@newsteve](https://forum.kirupa.com/u/newsteve)
#### Post date: [May 21, 2008, 4:06pm UTC](https://forum.kirupa.com/t/special-button-function/260122/5 "2008-05-21T16:06:28Z")

</div>

> [@randomagain;2329183](#):
>
> timeline is \*\*\*\* and \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* to make a point

Not sure what you mean with all those asteriks…??? Or much else of what you are trying to say… pretend Im in grade 4…

[quote=randomagain;2329183]

you shouldn’t be trying to move around the timeline with even basic AS

you will need to make pages \_visible = false and \_visible = true

with the same priniple as the button code

…

plus it is in a function… two plus[/quote]

---

<div class="post-metadata">

### Author: ![newsteve](https://avatars.discourse-cdn.com/v4/letter/n/5f8ce5/32.png) [@newsteve](https://forum.kirupa.com/u/newsteve)
#### Post date: [May 21, 2008, 4:22pm UTC](https://forum.kirupa.com/t/special-button-function/260122/6 "2008-05-21T16:22:44Z")

</div>

Oh I see…

All of the menus are appearing/disappearing by toggling on or off the visibility.  
However I also want an arrow to appear that kind of indicates which menu button was pressed to get to the newer menu which appears… the way I can think of doing this is via the timeline, with the arrow in different positions depending on the frame.  
Im sure there is a way to make said arrow appear on stage with \_visible = true as well, and I could modify its x and y coordinates, but I would have have the cooridinates correspond to the current coordinates of the button that was just pushed, but that kind of actionscript is a little above my level.

So this can all lead to a nice question:

I have 4 menus with 5 buttons in each menu. Only the top menu (menu1) is visible at the beginning. User hits any of the 5 buttons in menu1 and onRelease:

- button that is hit stays at 100% alpha, others fade to 50%
- red arrow appears below button that was hit.
- 2nd level menu appears below

(process of course starts all over again for this new menu).

Menu’s disappearing/reappearing is no problem. Im halfway there on the alpha fade issue, but have no idea how to do this arrow…

Anyone…?

Thanks!

---

<div class="post-metadata">

### Author: ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)
#### Post date: [May 22, 2008, 6:09am UTC](https://forum.kirupa.com/t/special-button-function/260122/7 "2008-05-22T06:09:32Z")

</div>

import mx.transitions.Tween;

//i assume that your arrow remains on the root level.

//press on any button or menu item

var tw:Tween=new Tween(arrow\_clip, “\_x”, mx.transitions.easing.None.easeIn,arrow\_clip.\_x,\_root.\_xmouse,2, true);

// put the above code in a function and call it with every menu item click (when it is selected);
