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

**URL:** <https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924>\
**Category:** flash\
**Created:** [February 27, 2002, 11:49pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924 "2002-02-27T23:49:11Z")\
**Posts on this page:** 13\
**Page:** 1

<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:** [February 27, 2002, 11:49pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/1 "2002-02-27T23:49:11Z")

</div>

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

```auto
    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.

---

<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:** [February 28, 2002, 12:27am UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/2 "2002-02-28T00:27:56Z")

</div>

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

---

<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:** [February 28, 2002, 12:36am UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/3 "2002-02-28T00:36:34Z")

</div>

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

---

<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:** [February 28, 2002, 12:43am UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/4 "2002-02-28T00:43:05Z")

</div>

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.

---

<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:** [February 28, 2002, 12:48am UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/5 "2002-02-28T00:48:16Z")

</div>

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]

---

<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:** [February 28, 2002, 12:54am UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/6 "2002-02-28T00:54:33Z")

</div>

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

---

<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:** [February 28, 2002, 7:36am UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/7 "2002-02-28T07:36:51Z")

</div>

Don’t have it…\rpom 0]

---

<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:** [February 28, 2002, 6:27pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/8 "2002-02-28T18:27:15Z")

</div>

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

---

<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:** [February 28, 2002, 8:17pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/9 "2002-02-28T20:17:43Z")

</div>

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]

---

<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:** [March 1, 2002, 5:26pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/10 "2002-03-01T17:26:12Z")

</div>

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.

```auto
 \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

---

<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:** [March 1, 2002, 10:06pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/11 "2002-03-01T22:06:15Z")

</div>

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]

---

<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:** [March 1, 2002, 10:47pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/12 "2002-03-01T22:47:51Z")

</div>

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

---

<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:** [March 7, 2002, 11:01pm UTC](https://forum.kirupa.com/t/loading-colors-from-an-array-array-problems/2924/13 "2002-03-07T23:01:10Z")

</div>

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