# Prototype advice?

**URL:** https://forum.kirupa.com/t/prototype-advice/19574
**Category:** Uncategorized
**Created:** [April 29, 2003, 3:13pm UTC](https://forum.kirupa.com/t/prototype-advice/19574 "2003-04-29T15:13:10Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![kdzines](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@kdzines](https://forum.kirupa.com/u/kdzines)
#### Post date: [April 29, 2003, 3:13pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/1 "2003-04-29T15:13:10Z")

</div>

hey,

I am about to start a new website and i am wondering about how to write a prototype function for it. I am using flash MX.

i have never written prototypes before, but have used a couple (especially the preloader prototype in best of Kirupa - brilliant)!

What i want to do sounds pretty simple but i always have problems with it.

basically there are 50 odd text buttons throughout the site, and when a user clicks one, i want the colour to change (like in html when you have a ‘down state’).

Now i want to write a prototype using setRGB that can be referenced by all buttons throughout the site. I also want it work so that when one button is clicked, all other buttons return to their original colour.

Has anyone written a code like this before? I don’t really have any idea about how to write protoypes (i have read everything on kirupa) and need some advice/code.

If you can help, or have a link to a really comprehensive prototype tut, please let me know.

Thanks in advance,

Kd

---

<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: [April 29, 2003, 5:35pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/2 "2003-04-29T17:35:17Z")

</div>

Create 3 Movie clips on the stage that act as buttons. Give them the instance names “button1”, “button2”, and “button3” (no quotes).

Now apply these actions to a frame in the timeline.

[AS]//array to store button instance names  
var buttonArray = [“button1”, “button2”, “button3”];  
//create the prototype call changeColors  
MovieClip.prototype.changeColors = function() {  
//create for loop to go through the buttonArray list  
for (var i = 0; i\<buttonArray.length; i++) {  
//create color object that targets each clip in the array  
var myColor = new Color(this.\_parent[buttonArray\*]);  
//if the instance name in the current position in the array is not equal to this clips name  
if (buttonArray\* != this.\_name) {  
//set the RGB value to 0x000000 (black)  
myColor.setRGB(0x000000);  
} else {  
//else if it is the same as ths clips name  
//set the RGB to 0xFF0000 (red)  
myColor.setRGB(0xFF0000);  
}  
}  
};  
//onPress is self explanitory  
//changeColors is the prototype it calls when you press  
button1.onPress = changeColors;  
button2.onPress = changeColors;  
button3.onPress = changeColors;[/AS]

But with using setRGB keep in mind that the entire clips color changes, so this only works for solid color shapes, so it would be best to have the button label on a layer above the actual movie clip so that doesn’t get changed to the same color. Or you could use setTransform to do more advanced color changes, but I suck with that, so I am not really the one to get into explaining that.

---

<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: [April 29, 2003, 6:15pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/3 "2003-04-29T18:15:09Z")

</div>

wow beta,

that’s some mad cool code! You continue to amaze me!

I am having a little problem. The prototype works great. When i click the button, it changes colour.

However when i click another button, this also changes colour, but the original button does not go black.

Looking at your code, i can’t see any problems at all, so i’m a bit stumped.

What i did for the buttons is that i made buttons as buttons, and then convert the button into a mc. I then opened the mc and added the code.

I believe that’s right? Maybe i’m doing something wrong that i cant see?

Please let me know if you know what i’m doing wrong and thanks again.

cheers,

KD

---

<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: [April 29, 2003, 6:19pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/4 "2003-04-29T18:19:51Z")

</div>

no. You put the code in the main timeline. The buttons themselves are just MovieClips. No need to make buttons and then convert them to movieclips.

---

<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: [April 29, 2003, 6:28pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/5 "2003-04-29T18:28:13Z")

</div>

i’m such an idiot!!!

Thanks Jubba for exposing my lack of logic. Tried it now and it works brilliantly.

I gotta learn more about prototypes and OOP. This is so much more effective for programming.

Know any really good books on OOP with flash. I gonna try and find a good one and read it cover to cover! (i’m never gonna have a social life again)!

Just kidding.

thanks to both of you

KD

---

<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: [April 29, 2003, 6:31pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/6 "2003-04-29T18:31:16Z")

</div>

this is for flash 5 but it should get you started:

[http://www.debreuil.com/docs/ch01\_Intro.htm](http://www.debreuil.com/docs/ch01_Intro.htm)

---

<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: [April 29, 2003, 8:13pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/7 "2003-04-29T20:13:48Z")

</div>

I am glad you got it working kd.

As for OOP, the link Jubba supplied is a great source, but just to warn you… OOP is known for causing migrains… it requires you to sort of change your thought pattern on scripting so it can be a pain if you are used to 1 method. I for one am horrible at OOP because I got used to my method, I really should try harder to learn OOP though :-\ 😛

---

<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: [April 29, 2003, 10:35pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/8 "2003-04-29T22:35:08Z")

</div>

right guys,

thanks for the link (and the advice - beta).

I have a related problem now that is confusing me.

So the buttons change colour now, but if i want to make the buttons do anything, it all goes horribly wrong!

For instance:

i want to click the button, change its colour and pass a variable like

\_root.Move = 1;

Now as we established the buttons are in fact MCs, so i go into the mc and add this:

this.onPress = function(){  
\_root.Move = 1;  
}

When i test this, the variable is passed to my animation script no problem, but now the button doesn’t change color!

what do i do? i tried going into the mc and turning the button into an actual button and then adding on(press){etc}

but again this wipes out the colour changing on the button.

Any ideas?

thanks as always,

Kd

---

<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: [April 29, 2003, 11:30pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/9 "2003-04-29T23:30:20Z")

</div>

the problem is that you’re replacing the onPress event handler assigned before with the new one. you use:

```auto
button1.onPress = function() {
this.changeColors();
_root.Move = 1;
};

```

😉

---

<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: [April 29, 2003, 11:40pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/10 "2003-04-29T23:40:56Z")

</div>

Yep… what kax said 🙂

---

<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: [April 29, 2003, 11:41pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/11 "2003-04-29T23:41:50Z")

</div>

Yep… what LiB said 😛

---

<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: [April 29, 2003, 11:43pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/12 "2003-04-29T23:43:48Z")

</div>

Yep… what Jubba said lostinbeta said kax said. 😛 😛

---

<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: [April 29, 2003, 11:47pm UTC](https://forum.kirupa.com/t/prototype-advice/19574/13 "2003-04-29T23:47:08Z")

</div>

You guys are good - and funny! hehe

thanks it now works great. This is the start of great things…

cheers all,

KD

---

<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: [April 30, 2003, 12:25am UTC](https://forum.kirupa.com/t/prototype-advice/19574/14 "2003-04-30T00:25:26Z")

</div>

::does the jig:: Congrats :beam:

---

<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: [April 30, 2003, 12:28am UTC](https://forum.kirupa.com/t/prototype-advice/19574/15 "2003-04-30T00:28:57Z")

</div>

:: slaps beta ::

---

<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: [April 30, 2003, 12:30am UTC](https://forum.kirupa.com/t/prototype-advice/19574/16 "2003-04-30T00:30:08Z")

</div>

Grrrr 😠 Take this Jubbsy Malone

:trout: :trout: :trout: :trout: :trout: :trout: :trout: :trout: :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: [April 30, 2003, 12:31am UTC](https://forum.kirupa.com/t/prototype-advice/19574/17 "2003-04-30T00:31:26Z")

</div>

:: kicks beta ::

psssshhh… punk 😛

---

<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: [April 30, 2003, 12:33am UTC](https://forum.kirupa.com/t/prototype-advice/19574/18 "2003-04-30T00:33:52Z")

</div>

Don’t be jealous of my mad skillz Jubbo… [size=1]::lost slinks into dark corner and hides::[/size]

---

<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: [April 30, 2003, 12:34am UTC](https://forum.kirupa.com/t/prototype-advice/19574/19 "2003-04-30T00:34:17Z")

</div>

ha, I am jealous, but thats not why I was slappin ya.

---

<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: [April 30, 2003, 12:38am UTC](https://forum.kirupa.com/t/prototype-advice/19574/20 "2003-04-30T00:38:18Z")

</div>

Well… you helped create me, so I don’t see why you are jealous… so it can’t be that… so that really does mean you slapped me because you hate me ☹ You created me, now you want to toss me aside!!! :\*(

[size=1]I think we hijacked this thread :-[/size]

[Next page](https://forum.kirupa.com/t/prototype-advice/19574.md?page=2)
