PDA

View Full Version : dim buttons with array?


jdulberg
11-25-2003, 10:23 AM
Hello, I have 6 "status" buttons as movieclips... and I have a separate menu with the same options as the 6 status buttons. When I click a menu option from that separate menu, I'm trying to dim out the 5 buttons that are inactive leaving the item chosen active.

Here is the code that I have so far but when I click one of the menu items, all of the buttons dim instead of all but the item clicked.


var buttons = [_root.animations, _root.photos, _root.drawings, _root.cult, _root.brochure, _root.powerpoint];
dobuttons = function () {
for (var j=0; j < buttons.length; j++) {
if (buttons[j] !== this) {
buttons[j]._alpha = 50 ;
buttons[j].gotoandplay("off");
}
else {
buttons[j]._alpha=100;
buttons[j].gotoandplay("on");
}
}
}


The above function is put in the root and called when a menu item is clicked.

If you have any suggestions, let me know!

Thanks :)

Jason

tg
11-25-2003, 12:53 PM
code looks ok, made one change to your function... look at this:


//a,b,c are movie clips on the main timeline
var buttons = [_root.a, _root.b, _root.c];
dobuttons = function (me) {
for (var j = 0; j<buttons.length; j++) {
if (buttons[j] !== me) {
buttons[j]._alpha = 50;
buttons[j].gotoandplay("off");
} else {
buttons[j]._alpha = 100;
buttons[j].gotoandplay("on");
}
}
};

a.onRollOver=function(){
dobuttons(this);
};
b.onRollOver=function(){
dobuttons(this);
};
c.onRollOver=function(){
dobuttons(this);
};

jdulberg
11-27-2003, 09:09 AM
Hello tg, thanks for your reply!

I tried the code that you included however I cannot get it to work properly. I changed it a bit in attempt to make the buttons know which should be on and which should be off after clicking several of their associated links. The problem is that when I click a link for "animations" for example, its associated indicator button stays _alpha=50 while all the others change.... essentially, its the opposite of what I want. The other thing that I noticed is when I toggle the links, the indicator buttons light up almost randomly.

I attached a test version of the script so you can see the problem that I am having.... note: I am using html links to control the flash movie.

Any suggestions are greatly appreciated!

Thanks :)

Jason

tg
12-01-2003, 01:20 PM
jason, don't know if this is what your after, but heres what i did...

first i commented out all of your code residing on all of your mcs, and i placed the code i thought you needed on the first frame of the main timeline so it looks like this:

var buttons = ["Animations", "Photos", "Drawings", "Cult", "Brochure", "Powerpoint"];
for (var i in buttons) {
//trace(_root[buttons[i]]);
_root[buttons[i]]._alpha = 25;//initialize all buttons to alpha of 25
_root[buttons[i]].onRollOver=function(){
//tell the mc to play the 'on' frame, set the alpha to 100
this.gotoAndPlay("on")
this._alpha=100;
};
_root[buttons[i]].onRollOut=function(){
//tell the mc to play the 'off' frame, se the alpha back to 25
this.gotoAndPlay("off");
this._alpha=25;
};
_root[buttons[i]].onRelease=function(){
//when any button is released, it opens a page with a name corresponding to the name of the mc.
this.getURL(this._name+".htm","_top","get");
};
}


hope this makes since to you, and does what you want.

jdulberg
12-01-2003, 02:51 PM
Hi tg, thanks for the code!

Your code is very helpful and appears more efficient than what I had. I have a couple questions however. How can I control the buttons using my html menu as well as the flash menu? Basically when I click on the html link OR the flash button, that button should light up while the others dim. The way that I had it before was that when the link is clicked, flash detected which variable was sent in the link and sends that variable to the old "dobuttons" function.

ie: dobuttons("Animations"); where Animations is sent from the html link. And dobuttons is the controller for a buttons on/off state.

There are a couple variables being sent from the html link which flash uses to display the buttons. Ie. if a certain variable isn't sent through the link, all of the buttons are _enabled=false.

I'm sure that this change is doable but I can't seem to figure it out on your coding.

Does that make any sense? Let me know if you need me to clarify :)

Thanks again!!

Jason

tg
12-01-2003, 04:20 PM
oh.. i missed that html -> flash interaction... i'll take another look at it later.

jdulberg
12-01-2003, 04:34 PM
Awesome, thanks! Here's an example of what is being passed through the html link to flash.

window.document.statustext.SetVariable("statusbar.statussec", sec);

"statussec" is an integer. So if statussec=0 for example, all but the "Animations" button will _alpha=25.

Thanks again!

Jason

tg
12-01-2003, 06:13 PM
try this... made some slight change to your htm files also, so make sure you use the htm files in the zip...

its still alittle buggy, but now its just a question of logic flo ie which events are happening when.

ive used onEnterFrame and an if statement to capture when the statussec variable changes value, but thats not really ideal. what would be ideal would be to set up a listener, that triggers the changes when the value is changed... should be possible, i've already kinda spent too much time on this.

anyway. here's the file.

jdulberg
12-02-2003, 01:34 PM
Thank you very much, I appreciate you spending the time! Everything but one item works as planned... I can click on the flash buttons and they load the associated page however the button that I click doesn't light up and dim the others. Was that part of the logic flow question that you mentioned?

Jason

tg
12-02-2003, 04:11 PM
nope... it was working for me with limited testing... the problem i was getting, was that i would mouseover/click a button (this worked ok), and the page would change, then i would click one of the html links and the corresponding button would change (still good), but when i mouse over another button on the flash menu after doing the above 2 steps, the new button would light, but the other would not dim... should be an easy fix, but no time again today...

btw do you know any wordXP to xml converters?... thats my current mission.