im having a problem trying to find out how to make a button stay in its rollover state after
being clicked and then when another button is clicked switch it to that one ,and so on.
please help, ive looked everywhere
I think i have an idea what you want to do. I will look into it when i get home this afternoon (probably in another hour or so) and see if i can sort something out for you.
This is actually not the color function you want but the concept is the same. You would just edit the button states to be colors instead of positions. The area you want to concentrate on is the stick function which is what makes the button stay on the down state until another button is pressed.
If you need more explanation on the code let me know.
Inside of the buttons (grayButton_mc) you have the labels and all the states of the button (over, down and out) the hit area is the same graphic with it's alpha set to 0 and it is also used as the mask for the button. In your case you may most likely not need the mask since you are doing color transitions and not graphic animation. Everything else should be self explanatory
I tried as much as possible to comment everything in the code for you but i will go more in depth. the first section of code i put the stop action for obvious reasons and then i defined a variable that holds the value of what the current page is. The page that is currently loaded on the screen. I do not assign a value to that as yet because that is done when you press the buttons. If you notice when you load up the movie nothing appears on the screen except the menu and no buttons are selected. You would need to change the code and add code to fix that for the initial page that you want loaded.
Code:
stop();
// create variable to track current page for button states
var currentPage;
The 2nd set of code creates a movieclip called holder_mc on the root timeline that will be holding your content and then moves that empty clip to the center of the stage. you could of course do it differently since there are many methods of loading content. Just use your method.
Next i assigned the button states. Instead of writing out all the code under each button I created functions that assigned the actions. I am only posting the code for 1 button but it is the same for all the other 3. In the onRollover, onRollout and onRelease of each button, the button passes itself to the rollover(), rollout() and stick() functions respectively where it goes and does the actions in that function The only exception is the loadContent() call in the onRelease that passes the name of the movieclip that it wants to load in the content area.
all of those buttons point to the functions below. I will go through each one separately. the rollover(movieName) and rollout(movieName) functions receive the name of the button that was rolled over and out and tests to see if it is actually the current page that is loaded. If it isn't then it plays the over state of that button otherwise it does nothing since it will be in the down state. And you don't want the rollover and rollout action occurring if it is in the down state.
Code:
function rollover(movieName){
if (currentPage != movieName){
movieName.gotoAndPlay("over");
}
}
function rollout(movieName){
if (currentPage != movieName){
movieName.gotoAndPlay("out");
}
}
On release of the button the stick(movieName) function is called and receives the name of the button to stick in the down position. If it is not then it plays the rollout or out state of the button that is currently in the down state then sets the current page to the page that you want to load then goes and stops at the down state of that new button that was pressed.
Code:
function stick(movieName){
if (currentPage != movieName){
currentPage.gotoAndPlay("out");
}
currentPage = movieName;
currentPage.gotoAndStop("down");
}
at the same time it also loads the content for that new page into the movieclip you created at the beginning of the code. It passes the name of the content movie you want to load(attach) from the library or file system (the method would vary based on the method you choose to load your content). it then put that content into the holder movieclip with an instance name of the movie being the same name as the movie being loaded and puts it at level 1. If you are just attaching the content from the library then remember that you need to export each of the content movieclips for actionscript.
Code:
function loadContent(movieName){
holder_mc.attachMovie(movieName, movieName ,1);
}
and there you have it. I hope that was good enough for you. Let me know if you have any more questions about it.
ive copied the code i needed and at the moment ive only done 1 button (about)
it all works except from once ive clicked it, when i rollover it again it goes back to
the first frame of the button.
could you please tell me what ive done wrong.
before i look at the file i can already guess it is either in the if statement or setting of the variable or a wrong stop code on the button but i will let you know for sure after i look at the file
Actually it was your frame names. remove the _ from in your names and code _out _down _over make then out, over and down. Flash has a tendency to use the _ for buttons a little more than you may want sometimes. the problem is that you are actually sending too much information to flash when you use the _over so flas looks at that as a button function and treat it that way regardless of what other code you have assigned to the function. Flash "knows" that once it encounters an _over that it is to automatically jumps to that frame in a button. So even if you have other code there, flash will ignore it. Removing the _ will fix that problem.
the way im used to linking the buttons to the pages is to make frames on the root timeline with labels saying the name of the pages and then putting in a (gotoAndPlay("E.G")
but i dont know how to make the code that we've been doing to do that
how do you do it
thanks
you could do it one of 2 ways. Either change the loadContent function to what is below and make sure that the release statement passes the name of the label that it needs to go to.
thanks
all the links are working now
at the start of the timeline it plays the first button but how do i get the button to stop on its down state automatically just as if it has been clicked
thankyou for all your help