Clicking boxes and changing color

I’ve been trying to copy footers from this site just to see if I could make them. And well, i’m kinda trying to make one like ahmed’s. Where when you click a square it changes from grey to white, and then back if you click it again. but I’m not trying to have it save designs like his (i’m not nearly that good). Here’s what I’ve got so far. I’ve just got 2 squares, but when i click one, they both turn white, why? Maybe I shouldn’t use alpha, but that’s only way of changing colors i know of.

NWC
:trout:

the problem when using buttons (actually, it’s a pretty common problem) is that scripts in button symbols are referenced to the timeline, not to the button itself.

either use movieclip symbols or instead of this use the instance name of the button. =)

lol i missed this thread

I used a movieclip with two frames, one with a white square and another with a grey one. I assigned this onRelease function on the mc’s:

(this._currentframe == 1)? this.gotoAndStop(2) : this.gotoAndStop(1)

and that basically detects what frame are you on and goes accordingly to the other frame :slight_smile:

thanks ahmed and kax, but Ahmed, yours is just a bit too advanced for me right now :). I tried making it squarename._alpha but then i get tons of errors? Here’s a few lines of code right now (2354 is the button’s instance name):

if (2354._alpha == 100){
2354._alpha = 0;
} else {
if(2354._alpha == 0){
2354._alpha = 100;

i dont think MC and var names can start with numbers :slight_smile:
other than that it should be fine :slight_smile:

if you want to use only numbers as the instance names…

on (release) {
	if (this["2354"]._alpha == 100) {
		this["2354"]._alpha = 0;
	} else {
		this["2354"]._alpha = 100;
	}
}

but wouldn’t it be easier like button1, button2, button3 and so on… ? :wink:

yeah and it really isn’t good practice to use numbers to start variables. you may confuse them later on as constants:

if (this["23456"] == 12.32) {}

ugh, just confusing. and you can translate ahmed’s code from above as follows:

if (this._currentframe == 1) {
this.gotoAndStop(2);
} else {
this.gotoAndStop(1);
}

i must say, ahmed i’ve never seen the question mark operator used that way. good way of using it there.

lol yeah… i don’t know how come it’s not so common, i find it a useful replacement for simple if-statements :slight_smile:

Originally posted by ahmed
lol yeah… i don’t know how come it’s not so common, i find it a useful replacement for simple if-statements :slight_smile:

yup… i use it all the time! =)

oh yeah, i use them all the time and it freaks out my C++ professors cause they’ve either never seen them or never expected any of their students to know how they work.

thanks guys. I was just gonna name the squares by their row and column. like 14 would be row 1 column 4, but oh well, i’ll name them something else i guess :). Thanks for all your help. And watch out thoriphes, i’m trying to make something like the aol/e-mail on your footer. That’s a very cool effect.

Thx, NWC
:trout:

i use naming like ‘box4_8’ (x:4, y:8) :slight_smile: