[mx] make mcs act like true buttons - prototype

hey everyone,

i have a site with all mc buttons, and the site is spread over a few scenes(arghh - i know, but this what it is)!

I have used a great protoype that lost wrote for me a while back:

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=21939

so with his prototype, when you click an mc, it makes that on “highlight” and makes all the other ones in the array “lowlight”.


//array to store button instance names
var navTopArray = ["company", "commissions", "projects", "press", "contact", "credits"];
//create the prototype call changeColors
MovieClip.prototype.navTopColors = function() {
	//create for loop to go through the buttonArray list
	for (var i = 0; i<navTopArray.length; i++) {
		//create color object that targets each clip in the array
		var myColor = new Color(this._parent[navTopArray*]);
		//if the instance name in the current position in the array is not equal to this clips name
		if (navTopArray* != this._name) {
			//set the RGB value to 0x000000 (light)
			myColor.setRGB(0xffffff);
		} else {
			//else if it is the same as ths clips name
			//set the RGB to 0xFF0000 (dark)
			myColor.setRGB(0x7f7f7f);
		}
	}
};

But for this site i have a big problem. When you enter each scene, the relevant button is highlighted - which i did by putting this code :


_root.nav.projectssubnav.projectssub4.navSubColors();

and when the user clicks another button, they go to another scene where another button is lit up.

But now i want to set it so that on rollover, each of the other buttons lights up in a third colour, and returns to its lowlight on rollout. BUT i want the button for the current scene to always remain highlighted.

Now i can see this being a problem with the protoype i have, so does anyone know i good way round this?

I am used to html where you have up, over, down states and that is what i am trying to recreate.

I really hope there is a good way to do this using a prototype, otherwise its gonna take forever as there are 80+ buttons.

Please help in whatever way you can,

thanks

kd

I can , quickly, think of a patch like:
[AS]
//array to store button instance names
var navTopArray = [“company”, “commissions”, “projects”, “press”, “contact”, “credits”];
//create the prototype call changeColors
MovieClip.prototype.navTopColors = function(aSelection) {
//create for loop to go through the buttonArray list
for (var i = 0; i<navTopArray.length; i++) {
//create color object that targets each clip in the array
var myColor = new Color(this._parent[navTopArray*]);
//if the instance name in the current position in the array is not equal to this clips name
if (navTopArray* != this._name) {
//set the RGB value to 0x000000 (light)
** if(navTopArray* != aSelection){
myColor.setRGB(0xffffff);
} else {
myColor.setRGB(0x6666ff);
}**
} else {
//else if it is the same as ths clips name
//set the RGB to 0xFF0000 (dark)
myColor.setRGB(0x7f7f7f);
}
}
};
[/AS]
if you don’t want the selected one to have a rollOver do the same to the the other colour in the if statement.

Now when you call the navTopColors function pass the selected section i.e.navTopColors(“company”);

hey another londoner!

Thanks for the help, but i’m still a bit confused. Could you write the actions for 1 of the buttons to help me understand how you call the function for the rollover colour, and how to sort out the button not chanigng colour?

Any idea where i can read up on functions, i really don’t get what happens to the things (inside the bracket), and how you pass the function and why?

any help you would be great

thanks mate

if u give me a bit of time i’ll try to put together a Fla file

wicked man!

thanks a lot!

Hi,
There you go.

arghh!

I’m well confused! I’m gonna try and figure out how to use your code in my project.

Thanks so much for all the help, i hope i can get this to work.

cheers,

hi again eki,

I’ve been going through your fla, and am seriously confused. I’m really sorry to bother you, but can you explain the init function?

i get the button functions (kind of). In the site i’m doing, i have 12-15 scenes and in each scene i have some nav buttons.

i always call the functions like this:



_root.company.onRollOver = function(){
this.navTopColors();
}
_root.company.onRollOut = function(){
this.navButtRollOut();
}

i get really confused when buttons are put in arrays etc for the button actions.
Cards on the table, i am rubbish with for actions, referencing arrays etc. It's something that i'm trying to learn, but i have to complete this site by Monday and i'm freaking out!

So if you can help in any way more, i would be soooo grateful!!!

thanks again

kd

right,

i finally figured out how to use the code to do exactly what i wanted - WOOHOO!

I still don’t really get it all, but if it works then i’m relieved!

Hey what do you do in london, r u in web design? Could have some work for you in the future.

Cheers for all the help,

kd

really sorry to bother you again, but i’m so close to getting this to work.

In your example, the buttons are on the stage, i just want to know how to change the code to target the buttons if they are all inside 1 mc called “nav”. Specifically i need to know how to have one of the buttons initially highlighted:

this.currentselection = “company”;

i’m so stuck on the pathing you have used.

please help me man!

Any explanation of :

butt.root = this.

i just can’t understand it!!

thanks

kd