Easy Movie Clip Random Color

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:

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.


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)

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

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