# Changing color trouble

**URL:** https://forum.kirupa.com/t/changing-color-trouble/62658
**Category:** Uncategorized
**Created:** [August 30, 2004, 10:50am UTC](https://forum.kirupa.com/t/changing-color-trouble/62658 "2004-08-30T10:50:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![headznet](https://avatars.discourse-cdn.com/v4/letter/h/34f0e0/32.png) [@headznet](https://forum.kirupa.com/u/headznet)
#### Post date: [August 30, 2004, 10:50am UTC](https://forum.kirupa.com/t/changing-color-trouble/62658/1 "2004-08-30T10:50:49Z")

</div>

I have a clip in my movie that changes colors randomly every timre it is loaded.  
hers the code:

MovieClip.prototype.randomColor = function() {  
var r = Math.floor(Math.random()\*255)+1;  
var g = Math.floor(Math.random()\*255)+1;  
var b = Math.floor(Math.random()\*255)+1;  
var c = new Color(this);  
c.setRGB(r \<\< 16 | g \<\< 8 | b);  
};

The problem is there are other movieclips I need to change to the same color.  
Heres the script I’m trying to do:

MovieClip.prototype.allSameColor = function() {  
getcolor = myColor.getRGB(the\_mc)  
myColor = new Color(this);  
myColor.setRGB(getcolor);  
};

---

<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: [August 30, 2004, 11:05am UTC](https://forum.kirupa.com/t/changing-color-trouble/62658/2 "2004-08-30T11:05:11Z")

</div>

1. random color can be achieved more easily using

```auto
col.setRGB(0xFFFFFF*Math.random());

```

1. to assign the color to multiple movieclips, just assign the random color to a variable and use that variable to apply colors… if you’re doing this more than once and all at once, then you can keep all the clips in an array and loop through that array to apply the color to each clip within.

```auto

_global.randomColor = 0xFFFFFF*Math.random();
coloredClips = [a_mc, b_mc, c_mc];
allSameColor = function() {
    for (var i=0; 0<coloredClips.length; i++)
        new Color(coloredClips*).setRGB(randomColor);
}

```

---

<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: [August 30, 2004, 3:09pm UTC](https://forum.kirupa.com/t/changing-color-trouble/62658/3 "2004-08-30T15:09:28Z")

</div>

Thanks for the great script senocular.
