I have a menu with 6 buttons. I have set up a variable called button pressed that tracks which button was pressed through numbers (if button 1 pressed, value of buttonPressed becomes 1 etc…) I want to test for which button was pressed as little as possible. If I say onClipEvent(mouseDown) it tells me that this can only be used for movie clips. How can i run a simple test to see which button was pressed?
okay. but then how would I create the test code that would be able to id which button was hit every time? Is there a general place that I can put the code like a standard code module or something and then every time a button is clicked, the program checks this test code to see what to do? for ex,
onClipEvent(mouseDown){ //any time the mouse is clicked check here
if 1…
if 2…
if 3…
}
but this gives me that error. Maybe I am putting the code in the wrong place? thanks
select a keyframe from your main timeline and than add the code below ,
[AS]_root.onMouseDown = function() {
switch (buttonPressed) {
case 1 :
trace(“button 1 pressed”);
case 2 :
trace(“button 2 pressed”);
//…
default :
trace(“no button pressed”);
}
};
[/AS]
cases are used to reduce the amount of if statements, especially when you have to check for several different possibilites to check for on one variable. The default is just like an else, only it works after testing all other possibilities, unlike an “if/else” which only checks the one possibility.
so that code seems to be working however, now whenever I click on a button, I have to click twice for it to recognize what I am clicking. any ideas why thats happening?
cases are used to reduce the amount of if statements, especially when you have to check for several different possibilites to check for on one variable. The default is just like an else, only it works after testing all other possibilities, unlike an “if/else” which only checks the one possibility.
this is why i used “case” ,thanx a lot for the discription paradox244
add the following code to your buttons :
[AS]
on(press){
_root.clickWhat(_name);
}[/AS]
than add the following to your main timeline
[AS]
function clickWhat(buttonPressed) {
switch (buttonPressed) {
case 1 :
trace(“button 1 pressed”);
case 2 :
trace(“button 2 pressed”);
//…
default :
trace(“no button pressed”);
}
};[/AS]
so the second solution appears to be working. Basically this is what I have done:
for my buttons i have this:
on(press){
_root.menu.clickWhat(1);
}
//This returns a 1 to the function clickWhat
For my main timeline I have this:
function clickWhat(buttonPressed) {
switch (buttonPressed) {
case 1:
trace("tables pressed");
break;
case 2 :
trace("accessories pressed");
break;
case 3 :
trace("specs pressed");
break;
case 4:
trace("Colors pressed");
break;
default :
trace("no button pressed");
}
};
The only problem that has been coming up is: When I click button 1, the trace box comes up and says tables pressed. It does the same for accessories. When I press specs and colors however, it traces the message twice. Any ideas why this is happening?
thanks
k
Creating engaging and entertaining content for designers and developers since 1998.