# Help on random color thing

**URL:** <https://forum.kirupa.com/t/help-on-random-color-thing/5458>\
**Category:** Uncategorized\
**Created:** [September 12, 2002, 12:55am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458 "2002-09-12T00:55:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostandfund](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@lostandfund](https://forum.kirupa.com/u/lostandfund)\
**Post date:** [September 12, 2002, 12:55am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/1 "2002-09-12T00:55:50Z")

</div>

QUESTION:

how do i go about having the color of one movie clip follow the same color of the random colored movie clip?

thanks to Mr.Ilyas’s nice and short tutorial, i did my FIRST actionscript, Random Colors. yeay!

i can’t seem to find the tutorial, but the coding went like this:

myColor = Math.round (Math.random()\*0xFFFFFF);  
myColoredObject = new Color (this);  
myColoredObject.setRGB(myColor);

i added this action to one movie clip. now, can i “synchoronize” the color of another movie clip to this one?  
Can anyone help me? heh heh

---

<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:** [September 12, 2002, 3:24am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/2 "2002-09-12T03:24:30Z")

</div>

WOO HOO SCORE! I got this one.

Inside your frame add these actions…

```auto
_root.onEnterFrame = function() {
	myColor = Math.round(Math.random()*0xFFFFFF);
};
MovieClip.prototype.makeColor = function() {
	myColoredObject = new Color(this);
	myColoredObject.setRGB(myColor);
};

```

now directly on your movie clip add this…

```auto

onClipEvent (enterFrame) {
	this.makeColor();
}

```

You can add that to as many movie clips as you want and they will all become the same random color value at the same 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:** [September 12, 2002, 3:26am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/3 "2002-09-12T03:26:27Z")

</div>

Here, I posted a .zip file with a .fla and .swf for examples.

PS: I only knew this one because I just got done doing a gradient experiment with random colors.

---

<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:** [September 12, 2002, 3:31am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/4 "2002-09-12T03:31:57Z")

</div>

thank you! thank you!. i’m at work right now, so i can’t try it out and see the result, but i’ll definitely work on it when i get home! thanks, 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:** [September 12, 2002, 3:36am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/5 "2002-09-12T03:36:37Z")

</div>

no problem fund:)

\<B\>EDIT:\</B\> This will only work in Flash MX. You didn’t state what version you had. Hopefully it is MX, because if it isn’t, I can’t help you out. I don’t know Flash 5.

---

<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:** [September 12, 2002, 3:55am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/6 "2002-09-12T03:55:56Z")

</div>

oh…

[SIZE=1]i have flash 5… [/SIZE]

well, maybe i can figure something out. oh. i gotta go.  
thanks anyways!

---

<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:** [September 12, 2002, 4:03am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/7 "2002-09-12T04:03:34Z")

</div>

oh ☹ that sucks. Maybe you will be able to figure it out in 5 from what I showed you.

Sorry for misleading you.

---

<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:** [September 12, 2002, 5:51am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/8 "2002-09-12T05:51:14Z")

</div>

I’m not all that sure what it is you’re trying to do. Perhaps if you both could explain it a little more to me, I could provide a 5.0 translation for LIB’s MX method.

---

<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:** [September 12, 2002, 5:56am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/9 "2002-09-12T05:56:09Z")

</div>

I can explain…

onClipEvent(enterFrame){  
myColor = Math.round (Math.random()\*0xFFFFFF);  
myColoredObject = new Color (this);  
myColoredObject.setRGB(myColor);  
}

That is applied directly to the movie clips actions. This randomly changes the color on enterFrame.

what lif wants is more than 1 movie clip that uses the same actions, but they all change to be the same color.

Although my example is kind of tacky, it shows exactly what my code above for MX does. Which is what lif wants.

[Check this link for example](http://www.8ballcreations.com/lostinbeta/ranColorSync.html)

---

<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:** [September 12, 2002, 6:32am UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/10 "2002-09-12T06:32:09Z")

</div>

\ ***I’m still writing this up… it doesn’t work yet.**

Well… I suppose there are a number of ways that could be done. Personaly, I’d use a “for. . . in” loop or maybe just a function.

for in loops detect all of something in something else, but I haven’t gotten them to work correctly, all of the time, on movie clips yet… we’ll see how this code works.

function colormall(){  
myColor = Math.round (Math.random()\*0xFFFFFF);  
for(mc in \_root){  
myColoredObject = new Color (mc);  
myColoredObject.setRGB(myColor);  
}  
}

can’t tell if that will work yet… but then you would just place the following on ONE of the clips… not all of them.

onClipEvent(enterFrame){  
\_root.colormall();  
}

The problem with this as I see it is that it will set any movie clip that’s on the stage… including those that you might not want to have set.

I’m thinking on this problem. 🙂

* * *

---

<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:** [September 12, 2002, 12:02pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/11 "2002-09-12T12:02:19Z")

</div>

Well, you don’t really need to run that enterFrame, do you? 🙂  
Basically, what you have to do is get that color out of the movie clip, on the \_root for instance:

```auto
_root.myColor=...

```

If you don’t want to do that, and that you have clips _clip1_ and _clip2_, you can call clip1’s color from clip2 (assuming that they are at the same depth):

```auto
myColoredObject = new Color (this);
myColoredObject.setRGB(_parent.clip1.myColor);

```

You’d have to put that in a handler of clip2 of course.

pom :asian:

Glad you like it!

---

<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:** [September 12, 2002, 12:07pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/12 "2002-09-12T12:07:43Z")

</div>

And since I’m such a nice guy, here’s a new one for you (I learnt it from the Bit himself, Keith Peters): put this on a movie clip

```auto
onClipEvent (EnterFrame){
   red=Math.sin(ra+=.02)*127+128; 
   green=Math.sin(rb+=.05)*127+128; 
   blue=Math.sin(rc+=.09)*127+128; 
   myCol=red<<16|green<<8|blue;
   myColored=new Color(this);
   myColored.setRGB(myCol);
}

```

I let you discover the effect (if the code works because I didn’t test it :P). This should be in the AS tricks section, it’s just soooo cool 🙂

pom =)

---

<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:** [September 12, 2002, 12:08pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/13 "2002-09-12T12:08:54Z")

</div>

I don’t understand your post Pom… 🙂

---

<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:** [September 12, 2002, 12:21pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/14 "2002-09-12T12:21:14Z")

</div>

Which one? 🙂

---

<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:** [September 12, 2002, 12:49pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/15 "2002-09-12T12:49:54Z")

</div>

the first one.

---

<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:** [September 12, 2002, 12:50pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/16 "2002-09-12T12:50:55Z")

</div>

oh and by the way that last one does work. nice effect.

---

<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:** [September 12, 2002, 1:11pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/17 "2002-09-12T13:11:20Z")

</div>

We need mind-readers… I just wanted to say that with the original piece of code, the variable myCol is located inside the movie clip, so if you want to access that variable, you can either put it in the \_root so that the second clip can call the same variable, \_root.myCol.  
Or clip2 can access the variable directly inside clip1 with the right path.

A classic variable scope issue…

pom 🙂

---

<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:** [September 12, 2002, 3:53pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/18 "2002-09-12T15:53:43Z")

</div>

Wow, very nice random color fade Ilyas. I worked out the same effect, but to nowhere near the effeciency of your code. I am using that from now on when I need to 🙂

Keith Peters is a genius no doubt.

---

<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:** [September 12, 2002, 4:03pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/19 "2002-09-12T16:03:12Z")

</div>

ahh… I see. No mind readers needed… sometimes I’m just slow. 🙂

---

<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:** [September 12, 2002, 9:13pm UTC](https://forum.kirupa.com/t/help-on-random-color-thing/5458/20 "2002-09-12T21:13:54Z")

</div>

woH! people. thanks for the help!  
(i had to read each posts about good twenty times to understand what you guys were talking about. okay, FINE. i lied. about fourty times… 🙂

i’m at work right now, but i’m gonna try mr.Ilya’s coding when i get home. the one with “\_parent.mc1” thing.

oh yeah, Mr. Ilyas, btw, what is it mean by:

(assuming that they are at the same “DEPTH”):  
that was your first post, i think. Is that the length of mc?

oh, boy. i can’t wait to come up with other questions to ask you guys to solve. haha. just kidding.

anyway, thank you.  
laf

[Next page](https://forum.kirupa.com/t/help-on-random-color-thing/5458.md?page=2)
