hi
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
Printable View
hi
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
This is not precisely what you are looking for, but may give you some idea.
http://www.flashscript.biz/memoclips...but_color.html
thanks for the help
if any one finds out any other ideas please post
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.
thanks for the trouble
ok here you go.
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.
thats exactly what i wanted
thank you so much for your help
could you go through the code for me
cheers v1knight
No problem, here you go.
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.
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.Code:stop();
// create variable to track current page for button states
var currentPage;
Code://create holder for content
this.createEmptyMovieClip("holder_mc", this.getNextHighestDepth());
holder_mc._x = Stage.width/2;
holder_mc._y = Stage.height/2;
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.
Code://*** Assign Button States ***
home_mc.onRollOver = function() {
rollover(this);
}
home_mc.onRollOut = function() {
rollout(this);
}
home_mc.onRelease = function() {
loadContent("home_mc");
stick(this);
}
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.
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 stick(movieName){
if (currentPage != movieName){
currentPage.gotoAndPlay("out");
}
currentPage = movieName;
currentPage.gotoAndStop("down");
}
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.
thanks for the explanation
ill have a go at editing it now
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.
thank you once again
im learning a lot from you
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.
or delete the loadContent function altogether and change the onRelease functions of all the buttons to beCode:home_mc.onRelease = function() {
loadContent("home");
stick(this);
}
function loadContent(movieName){
gotoAndPlay(movieName);
}
Code:home_mc.onRelease = function() {
gotoAntPlay("frameLabel");
stick(this);
}
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
add this at the top of your code
stick(about_mc);
substutute the about_mc for whatever button it is that you want the stick
thanks
i would of posted earlier but my internet conection went wrong
hi
ive heard that theres some kind of code or something that self activates the flash when you've put it on the internet instead of this anoying message saying "click or press enter to activate"
if this is true could you tell me
check out this site for the fix.
http://www.kirupa.com/developer/flash8/flash_fix.htm
cheers for that
hello again
please could you tell me what code says to play a certain frame
gotoAndPlay(20);
but you should always make it a habbit to give your frames labels so if you want it to play frame 20 then you should give frame 20 an identifying label of whatever it is to play then point the gotoAndPlay to the label.
gotoAndPlay("label");
cheers
Great information. Thank you. One quick question I have is if I wanted to load external swf's into the movie clip container instead of movieclips and have it function the same way, how would the actionscript differ?
Thanks.
not sure I follow exactly what you want. What section of the code are you referring to specifically?
hi
its me again
please could you tell me how to make a button make a different button stick in another movieclip, this is sticking by your code
thanks
well you could modify the code i sent before. you would still call the stick function to do it but instead of using stick(this) you would place the name of the target button you are trying to control. stick(newMovie.buttonToStick);
thanks again for the help
hI VI Knight, i dont know if your still about on here but i have read through your code on here and tried to recreate it within my own flash document.
the code i have added is in regards to another button instance. (about2_mc)
stop();
// create variable to track current page for button states
var currentPage;
//create holder for content
this.createEmptyMovieClip("holder_mc", this.getNextHighestDepth());
holder_mc._x = Stage.width/2;
holder_mc._y = Stage.height/2;
//*** Assign Button States ***
home_mc.onRollOver = function() {
rollover(this);
}
home_mc.onRollOut = function() {
rollout(this);
}
about_mc.onRollOver = function() {
rollover(this);
}
about_mc.onRollOut = function() {
rollout(this);
}
about2_mc.onRollOver = function() {
rollover(this);
}
about2_mc.onRollOut = function() {
rollout(this);
}
portfolio_mc.onRollOver = function() {
rollover(this);
}
portfolio_mc.onRollOut = function() {
rollout(this);
}
contact_mc.onRollOver = function() {
rollover(this);
}
contact_mc.onRollOut = function() {
rollout(this);
}
home_mc.onRelease = function() {
loadContent("home_mc");
stick(this);
}
about_mc.onRelease = function() {
loadContent("about_mc");
stick(this);
}
about2_mc.onRelease = function() {
loadContent("about2_mc");
stick(this);
}
portfolio_mc.onRelease = function() {
loadContent("portfolio_mc");
stick(this);
}
contact_mc.onRelease = function() {
loadContent("contact_mc");
stick(this);
}
//*** BUTTON FUNCTIONS ***
function rollover(movieName){
if (currentPage != movieName){
eval(movieName).gotoAndPlay("over");
}
}
function rollout(movieName){
if (currentPage != movieName){
movieName.gotoAndPlay("out");
}
}
function stick(movieName){
if (currentPage != movieName){
currentPage.gotoAndPlay("out");
}
currentPage = movieName;
currentPage.gotoAndStop("down");
}
function loadContent(movieName){
holder_mc.attachMovie(movieName, movieName ,1);
}
It all looks like it should work but it doesnt. The problem comes when it tried to load up the about2_mc movie file from the library, it just doesnt! it loads the about_mc movie fine, but not the about2_mc movie, it seems very strange to me and its starting to get on my nerves lol.
I have given the button tag the right name & i have kept the movie clip the same name as the tag. it just wont play.
Can you help?
did you tell the movie in the library to export itself for actionscript and give it an instance name to be reference in the library? This sounds like what your problem is.
1. Right click about2_mc in the library and choose linkage
2. Click the export for actionscript checkbox.
3. In the identifier text box make sure it says about2_mc (should be default)
4. click ok. This should make it work.
if you still have problems let me know.
thats brilliant, thanks VI Knight!
Happy new year dude.
just wondering what the code would look like if this code were put into an array? Is it fairly easy to do? Thanks.
which code would that be? If you are referring to the code onthe buttons then no. It won't work in an array. you can do it in a for loop but the name of the buttons would have to be of such that it would take incrementing numbers but other than that no array for coding.
i'm just wondering how to make the code simpler so if I had, let's say, 10 buttons on the stage named but1 - but10, what would be the best way to simplify the code so that I wouldn't have to rewrite the code for each button. Thank you so much for your help.
try this. You will need to keep the function section
Code:var maxButtons = 10;
for(i=1; i<maxButtons +1; i++){
this["but"+i].onRollover = function(){
rollover(this);
}
this["but"+i].onRollOut = function(){
rollout(this);
}
this["but"+i].onRelease = function(){
loadContent(this);
stick(this);
}
}
Great! I really appreciate your help!