PDA

View Full Version : Random Colors



deep cover
April 25th, 2002, 09:33 PM
I've perused the random color tuts, yet I'm still deadlocked somewhat on this issue.

I'm trying to make a square change colors randomly.

For example, I want the square to change from red, white, and blue, but randomly.

I know about Mcs and instance names and all that. I just need to know how to write the code. I know it starts with:

OnClipEvent (load)

and after the variable,

onClipEvent (enterFrame)
SetProperty....This where I get stuck. Any help will be of course appreciated.

ilyaslamasse
April 26th, 2002, 08:18 AM
I came up with that code : (prototype made by Yvant and corrected by Mama, rest by me :)) in the 1st frame of your animation, put a square (movie clip). Frame code :
MovieClip.prototype.colorize = function (r, g, b) {

(new Color(this)).setRGB(parseint(r+g+b, 16));

}Movie clip code :
onClipEvent (load) {

&nbsp &nbsp &nbsp &nbsp start = getTimer () ;

&nbsp &nbsp &nbsp &nbsp Tint = new Array () ;

&nbsp &nbsp &nbsp &nbsp for (i=0;i<3;i++) {

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Tint = new Array () ;
&nbsp &nbsp &nbsp &nbsp }

// red

&nbsp &nbsp &nbsp &nbsp Tint[0][0]="FF";
&nbsp &nbsp &nbsp &nbsp Tint[0][1]="00";
&nbsp &nbsp &nbsp &nbsp Tint[0][2]="00";

// blue

&nbsp &nbsp &nbsp &nbsp Tint[1][0]="00";
&nbsp &nbsp &nbsp &nbsp Tint[1][1]="66";
&nbsp &nbsp &nbsp &nbsp Tint[1][2]="cc";

// white

&nbsp &nbsp &nbsp &nbsp Tint[2][0]="ff";
&nbsp &nbsp &nbsp &nbsp Tint[2][1]="ff";
&nbsp &nbsp &nbsp &nbsp Tint[2][2]="ff";

}

onClipEvent (enterFrame) {
&nbsp &nbsp &nbsp &nbsp now = getTimer () - start ;
&nbsp &nbsp &nbsp &nbsp if (now>3000) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp i = random (3) ;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp trace (i) ;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.colorize (Tint [0],Tint [1],Tint [2]) ;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp start = getTpom 0]

ilyaslamasse
April 26th, 2002, 08:19 AM
This bloody Ezboard messed up everything. Gimme your address, I'll send the fla.

pom 0]

sinfiniti
April 26th, 2002, 08:31 AM
onClipEvent (load) {
aColors = [[255, 0, 0] , [255, 255, 255], [0, 0, 255]];
}
onClipEvent (enterFrame) {
if (Math.random()<0.05) {
nWhich = Math.floor(Math.random()*aColors.length);
obColor = new Color(this);
obTransform = new Object();
obTransform.ra = aColors[nWhich][0] ;
obTransform.ga = aColors[nWhich][1];
obTransform.ba = aColors[nWhich][2];
obColor.setTransform(obTransform);
}
}

make sure that the movie clip is white and the colors will work just fine (black won't change color so you can have a border if you want). if you want to add more colors to randomly display, just add the rgb values to the aColors array in brackets: [255,243,0] would be yellow(ish).
:)
jeremy





(edited to remove Emoticons)

ilyaslamasse
April 26th, 2002, 10:02 AM
Nice. I'm beginning to appreciate the notation, Sinf :D

pom 0]

deep cover
April 26th, 2002, 07:51 PM
Thanks five million poms, and sinfinite; pom alwayz comes to my rescue. Man I thank you.

Being that my acumen is killer screenwriting and novel crafting, maybe I can aid you one day with any writing project...I'll post the url to my dynamic website before long. Albeit I just started using flash, my website will look like a renowned flash Masta designedd and developed it. For I agree with the adage a Flash engineer once told me at a Flash seminar: "although you may not know how to code certain desired actions, as long as you know how to accomplish your end is what important"

Once again, thanks Pom...and Sinfiniti...u alwayz lend your expertise also...

deep cover
April 26th, 2002, 07:55 PM
seanhardaway@hotmail.com

that's my e-mail if you want send me tha a fla.

thanx Pom

ilyaslamasse
April 27th, 2002, 12:04 PM
I sent the fla, but I think you should try Sinf's method too. Shorter.

pom 0]