PDA

View Full Version : Multiple buttons


Peter Rush
03-07-2001, 08:06 AM
Hi...

I have a movie with 20 buttons of which the user can select three. when a fourth is selected, the first one is deslected, when another is selected, the second is deslected and so on.

I have a variable (called 'clicked') which counts how many clicks, and each button has a variable which shows if it has been clicked.

What I can't do is work out what to do when the variable "clicked" is greater than 3.

Any help would be great.

Rushy

Jesse
03-07-2001, 08:42 AM
I'm assuming your buttons are in MCs. So you can call your mcs 'button1', 'button2', etc, or name them in some numeric format. I'm also assuming you have some sort of MC structure where the 1st frame is the unselected version of the button graphic and the 2nd is the selected version.
Then each button could have this code:

_root:clickCount = _root:clickCount+1;
_root:selected = _root:selected+1;
_root["clickIndex"+_root:clickCount] = _name;
if (_root:selected>3) {
_root:selected = "3";
_root["clickIndex"+_root:clickCount-3].gotoAndStop(1);
}

That's just off the top of my head OK so if it doesn't work, don't be surprised, but it's the basic idea.

What it does:
- Incriments the counter which remembers how many buttons have been clicked
- Incriments the counter which shows how many are concurrently selected
- Sets the variable "clickIndex1" or 'clickIndex2', etc, to the name of the clip which was clicked. This part is keeping track of the order in which you clicked the buttons so we can unclick them in the same order.
- If the concurrently selected number > 3 we need to unselect one.
___- Rest the concurrent counter to 3.
___- Tell the 3rd last clip clicked (indicated by ["clickIndex"+_root:clickCount-3] ) to gotoAndStop it's unselected graphical state.

Cheers

Jesse

Peter Rush
03-07-2001, 08:57 AM
Thanks Jesse...

I think the code is exactly what I need but I am unsure at what point in the code to send my MC to frame 2 (it's selected state)

Rushy

[Edited by Jesse on 03-07-2001 at 05:15 PM]

Jesse
03-07-2001, 10:21 PM
Sorry Peter I didn't include that in the button code :)
The code I gave was also wrong, which I relized last night while in bed but I was sure oyu wouldn't mind wainting till the morning to hear the changes.

OK this should work great:

on (release) {
this.gotoAndStop(2);
_root:clickCount = _root:clickCount+1;
_root:selected = _root:selected+1;
_root["clickIndex"+_root:clickCount] = _name;
if (_root:selected>3) {
_root:selected = "3";
_root.target = (eval(["clickIndex"+(_root:clickCount-3)]));
_root[_root.target].gotoAndStop(1);
}
}

Cheers

Jesse

PS - I deleted your other post and put it in here so that people following this thread can see the entire process.