Help on random color thing


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);

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

WOO HOO SCORE! I got this one.

Inside your frame add these actions…

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

now directly on your movie clip add this…

onClipEvent (enterFrame) {

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:)

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.

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.

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.


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

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

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

Sorry for misleading you.

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.

I can explain…

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

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

*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);

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.


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. :slight_smile:

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


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):

myColoredObject = new Color (this);

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

pom :asian:

Glad you like it!

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

onClipEvent (EnterFrame){
   myColored=new Color(this);

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 :slight_smile:

pom =)

I don’t understand your post Pom… :slight_smile:

Which one? :slight_smile:

the first one.

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

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 :slight_smile:

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 :slight_smile:

Keith Peters is a genius no doubt.

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

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… :slight_smile:

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.