[FMX] Button Scripting/Variables

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.

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.

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


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.

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.

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

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

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.

k

:slight_smile: I did it on my lunch break. Here ya go

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?

the prototype idea would be much more complicated. This is the easiest way to do it.

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

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.

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.

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

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.

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

:slight_smile: no problem. good luck