# \[FMX\] Button Scripting/Variables

**URL:** <https://forum.kirupa.com/t/fmx-button-scripting-variables/28304>\
**Category:** flash\
**Created:** [August 12, 2003, 12:49pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304 "2003-08-12T12:49:36Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![NitroLiq](https://avatars.discourse-cdn.com/v4/letter/n/ea666f/32.png) [@NitroLiq](https://forum.kirupa.com/u/NitroLiq)\
**Post date:** [August 12, 2003, 12:49pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/1 "2003-08-12T12:49:36Z")

</div>

Can someone help me with out the best way to script several MCs (acting as buttons) so that on release(), the alphas on the others tween to 20. When you go to click one of the dimmed button, its alpha should tween back to 100 and the previous one that had the full alpha should now fade to 20.

Logically, I know I need to somehow implement a variable to check the state of the MC and an if statement to script the actual alpha tweens but I’m confused as how to actually implement it. where to put it etc.

If anyone has a small example of something like this or can point me in the right direction, I’d really appreciate it. Am trying to figure it out before my next project starts.

---

<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:** [August 12, 2003, 4:38pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/2 "2003-08-12T16:38:14Z")

</div>

on the movie clip, try something like the following  
[AS]  
onClipEvent(enterFrame){  
this.onPress = function() {  
//all other alphas fade up  
//this.\_alpha fade down  
}  
}

[/AS]  
If you put that on all of the movie clips, when they are clicked it should work. If you need help with the actual coding, I might be able to help you out.

---

<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:** [August 12, 2003, 5:06pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/3 "2003-08-12T17:06:47Z")

</div>

That would be great if you could help with the coding. Looking at your code, the function actions should be reversed:

```auto

onClipEvent(enterFrame){
        this.onPress = function() {
                 //this._alpha fade up
                //all other alphas fade down
                
        }
}

```

All the buttons should initially have alphas of 100%.

Now, wouldn’t I have to use variables to check the state of the other MCs? I spoke with thorophies yesterday and this is what he mentioned:

“Set one variable to be equal to the id or something of the button that’s being hovered then have each button check if it’s its own ID, if not, fade.”

I’m not that advanced yet so I’m not sure how to implement everthing in the MC itself.

Thanks for the help.

---

<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:** [August 12, 2003, 5:14pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/4 "2003-08-12T17:14:14Z")

</div>

Yeah thor is right. You could write a prototype function that would fade down the alphas of all the movie clips except the one that was clicked. You could have a variable for the name of the button and the function would fade all of the ones except the one that had its name passed to the function. I don’t have a lot of time right now to write code (I am at work) but I might be able to help you out later.

---

<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:** [August 12, 2003, 5:26pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/5 "2003-08-12T17:26:35Z")

</div>

That would be great if you could. I really want to learn this for my next project.

---

<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:** [August 12, 2003, 6:25pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/6 "2003-08-12T18:25:06Z")

</div>

Can you post a fla or something or do you want me to try from scratch?

---

<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:** [August 12, 2003, 6:28pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/7 "2003-08-12T18:28:40Z")

</div>

If you just want to post from scratch, that’s fine. Just make 2 or 3 circles and convert to MCs. That’ll get the idea across as far as the buttons go.

---

<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:** [August 12, 2003, 6:30pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/8 "2003-08-12T18:30:34Z")

</div>

k

---

<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:** [August 12, 2003, 6:45pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/9 "2003-08-12T18:45:29Z")

</div>

🙂 I did it on my lunch break. Here ya go

---

<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:** [August 12, 2003, 6:57pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/10 "2003-08-12T18:57:29Z")

</div>

Thanks for the example but the buttons should actually do the opposite. The button you click should remain at full alpha. The other MCs should fade. So if you click button 1, that’s the active button, the other two fade in the background. then when you click number 2, number 1 and 3 will fade in the background, etc.

Do you know how to do it using the prototype idea as well?

---

<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:** [August 12, 2003, 7:54pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/11 "2003-08-12T19:54:35Z")

</div>

the prototype idea would be much more complicated. This is the easiest way to do 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:** [August 12, 2003, 7:56pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/12 "2003-08-12T19:56:27Z")

</div>

OK here is what you wanted. All I did was move code around.

---

<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:** [August 12, 2003, 8:04pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/13 "2003-08-12T20:04:43Z")

</div>

Awesome. One last question, where is it initially setting the alpha? I want to edit all the buttons to start out at full alpha until you click or rollover the first button rather than everything defaulting to 20.

---

<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:** [August 12, 2003, 8:07pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/14 "2003-08-12T20:07:02Z")

</div>

it doesnt initially set the alpha. You would have to make a counter to do that. It is pretty straighforward. Just make a counter that goes up each time they click the button. If the counter is less than 1, alpha is 100.

---

<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:** [August 12, 2003, 8:19pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/15 "2003-08-12T20:19:55Z")

</div>

Can you point me to a tut for building a timer…never did that before? Sorry to be a pest.

---

<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:** [August 12, 2003, 8:23pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/16 "2003-08-12T20:23:27Z")

</div>

Don’t need a timer. Just a counter. make a variable and set its starting value to zero. every time you click one of the buttons, say variable +=1. Have a check saying if the variable is less than 1, all alphas are 100. Not a time, just a variable that goes up.

---

<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:** [August 12, 2003, 8:27pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/17 "2003-08-12T20:27:44Z")

</div>

I think I understand. I’ll give it a try. Thanks for all the help.

---

<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:** [August 12, 2003, 8:29pm UTC](https://forum.kirupa.com/t/fmx-button-scripting-variables/28304/18 "2003-08-12T20:29:26Z")

</div>

🙂 no problem. good luck
