Okay, I know this isn't the first topic on this subject… I've been Googling all day and I know there are various ways to go about this, but I am really struggling with implementing them.
Currently, I have a website with a very simple code that gives all the buttons in the menu an animated rollover and rollout state. When the buttons are clicked, I have a movie clip with all the content which goes to a specific frame label depending on which button is clicked. Very simple, no problems there.
But what I can't figure out how to do, is to add a variable so that when each button is clicked, it stays in the over state until another button is clicked (at which point I'd like it to go to the out state, while the new button would go to the over state.)
I found several examples of codes that do this, but I can't figure out how to modify them so that when a button is clicked, it also goes to a specific frame label in the content movie clip, so that the content for each section can be displayed.
and then here is a code I found through Googling that does work to make buttons stay pressed, but I don't know how to edit it so that whenever a button is clicked it still goes to a specific frame label in the timeline of a movie clip, the way I have it in the original code:
Could somebody please help me? I'm really very remedial when it comes to coding, I'm much more of a designer/animator but I really would like to get this to work.
//This gives the menus' quantity
var buttonNum:Number = 4;
//With this for cycle, the program will enable the scirpt for button[1,2,3,4].
for (i=1; i<=buttonNum; i++) {
this["button"+i].onRollOver = function() {
//This will check, that menu doesn't enabled yet. '!=' means, not equal.
if (this.clicked != "yes") {
this.gotoAndPlay("over");
}
};
//Same script, for the rollOut function on the four buttons.
this["button"+i].onRollOut = function() {
if (this.clicked != "yes") {
this.gotoAndPlay("out");
}
};
//Same for release function.
this["button"+i].onRelease = function() {
this.gotoAndStop("out");
//the other buttons will be 'enabled' for click, and doesn't 'click'-ed and this will be the clicked one, without function('enabled = false').
this._parent[_root.clickedButton].gotoAndPlay("out");
this._parent[_root.clickedButton].clicked = false;
this._parent[_root.clickedButton].enabled = true;
_root.clickedButton = this._name;
this.clicked = "yes";
this.enabled = false;
//Your mc got named, by the pressed menu's name. (textBTN_txt.text)
_root.on_txt.text=this._name +" in "+this.textBTN_txt.text;
};
}
If you want to use this script, just rewrite your menus button1, button2..etc. And give the right number for
Thank you so much for replying, I really appreciate it. And I also appreciate you breaking down the different parts of that code, that is helpful.
But the thing that I'm not understanding, is how to modify that code so that when clicked, while staying down, the buttons also go to a specific frame label in a specific movie clip. I tried combining the 2 different codes I had, but when I do that, it makes the button stop staying down after being clicked.
Do you know what I need to do to make both work? (Again, any help is very much appreciated!)
Okay, I got it working! But I'm sure there must be a way to do it without repeating so much of the same code. I just can't get it to work any other way though. This is what I have so far, and it does work (which is the most important thing), but if there's a better way I can do it, I would really appreciate it if somebody could point me in the right direction!
(I changed in content the menu names) + made a shorter script.
I hope it helps.
That is awesome! Thank you!
Okay, so there's just one more thing I'm wondering about... (Sorry!)
I was just wondering if there's a simple way to modify that code again, this time so that when people first open the file, the first button has already been selected (so they're already on what will be the home page, and the button will already be down?).
I think I know a way to fake it, but it would be great to know how it's properly done...
Sorry if I'm asking too much... Again I really really appreciate you being so helpful!
I made it, and it's makes a bit longer your script but I think there aren't any other ways for this, with that 'for' cycle, that you want to use for menus.
Okay, sorry, I have one more question. This is the last one, I promise!
I was just wondering...
How would I modify that code if I wanted to show the rollover animation on entering the frame? (so instead of already being clicked, it would show the rollover animation first and then stay down, as if somebody had rolled over it and then clicked it).
I tried just changing it to
Code:
if (!firstclick) {button1.gotoAndPlay("over");
but that didn't work so I'm not sure what I would need to change...
Again I really really appreciate you taking the time to help me with this. I'm great when it comes to design and animation but with coding I don't really know much at all.
If you can't help with that I understand though, you've already helped immensely.
On the version with the delay, the buttons are still clickable once they've already been clicked; if you click them again, it plays the rollout animation. Is there a way to prevent this?
The previous version works perfectly, but I would like to use the delay also, so if I could fix that one little bug it would be perfect...
That almost totally fixes it but I noticed for the button1/A, it still has the same issue until another button has been clicked... is there a fix for that?