Loading colors from an array (Array problems...)

I know that problem has been discussed recently, but I cant find the post. Here’s the prob :

    onClipEvent (load) {\r\r        myArray = new Object () ;\r\r        myArray = ["0x000000","0x111111",...] ;\r\r        for (i = 0;i<10;i++) {\r\r                attachMovie("form", "t"+i, i);\r\r                var mc = this["t"+i];\r\r                var colorful = new Color("mc" );\r\r                colorful.setRGB(myArray(i) );

In fact in the last line, i is put between [], but the Ezboard interprets it as italic, so…\rWell, that doesn’t work. It sets the RGB to 000000 (black). The problem is that setRGB isn’t used with “0x000000”, but simply with 0x000000, and I can’t seem to be able to put anything else than strings in my array.\rHELP !!!\rpom 0] \r\rPS : Basically that script puts instances of an object on the scene, and gives them colors that are stored in an array. That’s just the start of the script.

gotta run…\r\rdon’t use quotes in your color object declaration … new Color(mc);\r

With or without “”, it won’t work. Anyway it’s black. Don’t run !!!\rpom 0]

i don’t think you can input the elements of an array like that… i think you use angle brackets ("{}") not those brackets. it might help to change it.

If I trace (myArray(i)), still those bloody [], it works perfectly. It’s just that it’s a string, and not a… what is it by the way, that 0x000000 ??\rpom 0]

that would be hexadecimal values. if you’ve got AIM, contact me right now (thoriphes2k1). we’ll, you know, talk.

Don’t have it…\rpom 0]

you’re not allowed to spec hex numbers like that, you need to shift them…\r\rcolour.setRGB( 204<<16 | 153<<8 | 51);\r\radapt you’re method to use this syntax for dynamic colour.\r\rhere’s a chance to use a multidimensional array… \r\rcolours = [[204,153,51],[102,55,236],[89,201,145]];\rmyColor.setRGB( colours[0][0]<<16 | colours[0][1]<<8 | colours[0][2] );\r\ryou leave the quotes off of mc because it’s a variable, not a string literal.\r\rit might work both ways, but strictly speaking… ; )\r

Ou la la la !! Hang on just one minute… What the heck is that 204<<16 | 153<<8 | 51 thing ? I fear that this would be some kind of translation from decimal to hexadecimal, but the <<16 baffles me. Wild guess : 2 digits in hexa are coded on 8 bits, which would explain why 51<<0 works fine (0 being the starting bit, then 8 for the 2 following digits, and 16 for the last 2).\rAm I right ??\r\rAnyway, it works great. Thanks Supra, you’re just too good. I’ve been wondering : what do you do in real life ?\r\rpom 0]

actually, it was trying to solve this very problem that brought me to this forum. kirupa wrote a great dynamic colour change tutorial that saved the day for me.\r\r<< is a bitwise shift, shifts the left side by the number of places spec’ed on the right. so 101 << 2 = 10100. | is a bitwise or, which means it combines two numbers and keeps all the 1’s.\r\r1001010 bitwise or’ed with\r1100100 yields\r1101110\r\rsee how only to zeros produce a zero? everything else is 1.\r\rso in this case, you have three hex numbers which you wnat to combine into one big string. so you move the first one over 16 places, the second over 8 and leave the third where it is.

 \r\r011010110000000000000000\r\r        1101001100000000\r\r                10010100  yields\r\r011010111101001110010100

\rand there’s your string!\r\roh, and this is what i do in real life. ; )\r

Pretty much like in C after all. Still, 101 << 2 shifts by 2 digits on the left a binary number, I find it strange that it works as well with decimal numbers. But anyway, it works…\rpom 0]

right, i took a few liberties with the explaination …\r\r101 actually should have been its decimal equivilant - 5.\r\r

I just noticed there was a tutorial on random colors on this site…\rpom 0]