# Easy Movie Clip Random Color

**URL:** <https://forum.kirupa.com/t/easy-movie-clip-random-color/34770>\
**Category:** flash\
**Created:** [November 6, 2003, 5:05am UTC](https://forum.kirupa.com/t/easy-movie-clip-random-color/34770 "2003-11-06T05:05:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![El\_Phantom](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@El\_Phantom](https://forum.kirupa.com/u/El_Phantom)\
**Post date:** [November 6, 2003, 5:05am UTC](https://forum.kirupa.com/t/easy-movie-clip-random-color/34770/1 "2003-11-06T05:05:08Z")

</div>

Got kirupa’s code for Random color working so that you can just copy paste it into any movieclip you want to have the effect. Thought it might be good to post it up here for lazy people like me or AS noobs. :trout:

Enjoy guys, and let me know if there’s any problems with it.

[AS]

onClipEvent(load){

speed = 4000;

myColor = new Color(this);

function colorFunction(){

\_root.colorvar1 = Math.random()\*255;  
\_root.colorvar2 = Math.random()\*255;  
\_root.colorvar3 = Math.random()\*255;

}

colorFunction();  
setInterval(colorFunction, speed);

}

onClipEvent(enterFrame){

\_root.change1 = \_root.colorvar1 - \_root.oldcolor1;  
\_root.change2 = \_root.colorvar2 - \_root.oldcolor2;  
\_root.change3 = \_root.colorvar3 - \_root.oldcolor3;  
\_root.change1 = \_root.change1 / 10;  
\_root.change2 = \_root.change2 / 10;  
\_root.change3 = \_root.change3 / 10;  
\_root.oldcolor1 -= \_root.colorvar1 - \_root.change1;  
\_root.oldcolor2 -= \_root.colorvar2 - \_root.change2;  
\_root.oldcolor3 -= \_root.colorvar3 - \_root.change3;  
myColor.setRGB(\_root.change1 \<\< 16 | \_root.change2 \<\< 8 | \_root.change3);

}

[/AS]

–EP :bandit:

---

<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:** [November 6, 2003, 5:13am UTC](https://forum.kirupa.com/t/easy-movie-clip-random-color/34770/2 "2003-11-06T05:13:58Z")

</div>

How about this?  
[AS]  
MovieClip.prototype.colorFunction = function() {  
colorvar1 = Math.random()\*255;  
colorvar2 = Math.random()\*255;  
colorvar3 = Math.random()\*255;  
};  
MovieClip.prototype.loader = function() {  
speed = 4000;  
myColor = new Color(this);  
colorFunction();  
setInterval(colorFunction, speed);  
this.onEnterFrame=eFrame;  
};  
MovieClip.prototype.eFrame = function() {  
\_root.change1 = \_root.colorvar1-\_root.oldcolor1;  
\_root.change2 = \_root.colorvar2-\_root.oldcolor2;  
\_root.change3 = \_root.colorvar3-\_root.oldcolor3;  
\_root.change1 = \_root.change1/10;  
\_root.change2 = \_root.change2/10;  
\_root.change3 = \_root.change3/10;  
\_root.oldcolor1 -= \_root.colorvar1-\_root.change1;  
\_root.oldcolor2 -= \_root.colorvar2-\_root.change2;  
\_root.oldcolor3 -= \_root.colorvar3-\_root.change3;  
myColor.setRGB(\_root.change1 \<\< 16 | \_root.change2 \<\< 8 | \_root.change3);  
};  
myClipOnStage.onEnterFrame=function(){  
loader();  
}  
[/AS]  
myClipOnStage is just the instance name of a clip on the stage that you want to be effected, OR a dynamically created clip like so.

```auto

MovieClip.prototype.colorFunction = function() {
	colorvar1 = Math.random()*255;
	colorvar2 = Math.random()*255;
	colorvar3 = Math.random()*255;
};
MovieClip.prototype.loader = function() {
	speed = 4000;
	myColor = new Color(this);
	colorFunction();
	setInterval(colorFunction, speed);
	this.onEnterFrame=eFrame;
};
MovieClip.prototype.eFrame = function() {
	_root.change1 = _root.colorvar1-_root.oldcolor1;
	_root.change2 = _root.colorvar2-_root.oldcolor2;
	_root.change3 = _root.colorvar3-_root.oldcolor3;
	_root.change1 = _root.change1/10;
	_root.change2 = _root.change2/10;
	_root.change3 = _root.change3/10;
	_root.oldcolor1 -= _root.colorvar1-_root.change1;
	_root.oldcolor2 -= _root.colorvar2-_root.change2;
	_root.oldcolor3 -= _root.colorvar3-_root.change3;
	myColor.setRGB(_root.change1 << 16 | _root.change2 << 8 | _root.change3);
};
mc = createEmptyMovieClip("createdClip",1);
mc.lineStyle(100,0x000000,100);
mc.lineTo(1,.1);
mc._x=200;
mc._y=200;
mc.onEnterFrame=function(){
	loader();
}

```

edit: bah, i just tested this and it does not work as its supposed to… I tried and half did it though… if anyone wants to try to fix whatever i did wrong, go for it (it has to do with calling the colorFunction I think)

---

<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:** [November 6, 2003, 5:26am UTC](https://forum.kirupa.com/t/easy-movie-clip-random-color/34770/3 "2003-11-06T05:26:54Z")

</div>

Yeah, but I mostly posted this code up for people who don’t want all the complicated AS and just want to copy paste, without editing. Your code is good, but my intent was to strip it down to the bare minimum, for the purpose of education.

Thanks for the contribution regardless; I’m sure somebody will use it / add it to the library.

–EP

---

<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:** [November 6, 2003, 7:08pm UTC](https://forum.kirupa.com/t/easy-movie-clip-random-color/34770/4 "2003-11-06T19:08:23Z")

</div>

The only reason I did it was to further my education as well 😃 trying to get better with OOP
