Random Colors

I’ve perused the random color tuts, yet I’m still deadlocked somewhat on this issue.\r\rI’m trying to make a square change colors randomly.\r\rFor example, I want the square to change from red, white, and blue, but randomly.\r\rI know about Mcs and instance names and all that. I just need to know how to write the code. I know it starts with:\r\rOnClipEvent (load)\r\rand after the variable, \r\ronClipEvent (enterFrame)\rSetProperty…This where I get stuck. Any help will be of course appreciated.

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) { \r\r  (new Color(this)).setRGB(parseint(r+g+b, 16)); \r\r}

Movie clip code :

 onClipEvent (load) {\r\r&nbsp &nbsp &nbsp &nbsp start = getTimer () ;\r\r&nbsp &nbsp &nbsp &nbsp Tint = new Array () ;\r\r&nbsp &nbsp &nbsp &nbsp for (i=0;i<3;i++) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Tint*  = new Array () ;\r&nbsp &nbsp &nbsp &nbsp }\r\r// red\r\r&nbsp &nbsp &nbsp &nbsp Tint[0][0]="FF";\r&nbsp &nbsp &nbsp &nbsp Tint[0][1]="00";\r&nbsp &nbsp &nbsp &nbsp Tint[0][2]="00";\r\r// blue\r\r&nbsp &nbsp &nbsp &nbsp Tint[1][0]="00";\r&nbsp &nbsp &nbsp &nbsp Tint[1][1]="66";\r&nbsp &nbsp &nbsp &nbsp Tint[1][2]="cc";\r\r// white\r\r&nbsp &nbsp &nbsp &nbsp Tint[2][0]="ff";\r&nbsp &nbsp &nbsp &nbsp Tint[2][1]="ff";\r&nbsp &nbsp &nbsp &nbsp Tint[2][2]="ff";\r\r}\r\ronClipEvent (enterFrame) {\r&nbsp &nbsp &nbsp &nbsp now = getTimer () - start ;\r&nbsp &nbsp &nbsp &nbsp if (now>3000) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp i = random (3) ;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp trace (i) ;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.colorize (Tint* [0],Tint* [1],Tint* [2]) ;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp start = getT****

pom 0]

This bloody Ezboard messed up everything. Gimme your address, I’ll send the fla.\r\rpom 0]

onClipEvent (load) {\raColors = [[255, 0, 0] , [255, 255, 255], [0, 0, 255]];\r}\ronClipEvent (enterFrame) {\rif (Math.random()<0.05) {\rnWhich = Math.floor(Math.random()*aColors.length);\robColor = new Color(this);\robTransform = new Object();\robTransform.ra = aColors[nWhich][0] ;\robTransform.ga = aColors[nWhich][1];\robTransform.ba = aColors[nWhich][2];\robColor.setTransform(obTransform);\r}\r}\r\rmake 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).\r:) \rjeremy\r\r\r\r\r\r(edited to remove Emoticons)

Nice. I’m beginning to appreciate the notation, Sinf :smiley: \r\rpom 0]

Thanks five million poms, and sinfinite; pom alwayz comes to my rescue. Man I thank you.\r\rBeing 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”\r\rOnce again, thanks Pom…and Sinfiniti…u alwayz lend your expertise also…

[email protected]\r\rthat’s my e-mail if you want send me tha a fla.\r\rthanx Pom

I sent the fla, but I think you should try Sinf’s method too. Shorter.\r\rpom 0]