# Clicking boxes and changing color

**URL:** <https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716>\
**Category:** flash\
**Created:** [May 25, 2003, 3:31pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716 "2003-05-25T15:31:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaliWarCow](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@NaliWarCow](https://forum.kirupa.com/u/NaliWarCow)\
**Post date:** [May 25, 2003, 3:31pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/1 "2003-05-25T15:31:03Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 4:21pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/2 "2003-05-25T16:21:23Z")

</div>

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. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 4:32pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/3 "2003-05-25T16:32:24Z")

</div>

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:

```auto
(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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 4:44pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/4 "2003-05-25T16:44:39Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:02pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/5 "2003-05-25T17:02:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:04pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/6 "2003-05-25T17:04:20Z")

</div>

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

```auto
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… ? 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:08pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/7 "2003-05-25T17:08:48Z")

</div>

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

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

```

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:10pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/8 "2003-05-25T17:10:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:13pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/9 "2003-05-25T17:13:57Z")

</div>

> _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 🙂**

yup… i use it all the time! =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:14pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/10 "2003-05-25T17:14:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:36pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/11 "2003-05-25T17:36:31Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2003, 5:58pm UTC](https://forum.kirupa.com/t/clicking-boxes-and-changing-color/21716/12 "2003-05-25T17:58:24Z")

</div>

i use naming like ‘box4\_8’ (x:4, y:8) 🙂
