by ilyas usal
Some of you may have read Kirupa's tutorial about random colors, and you may
have found that it was very very complicated. Well don't worry, there is a much
easier method that I will explain here.
First you have to know that colors in Flash are represented by hexadecimal
values, that is to say numbers that look like:
myColor = 0xFF0055;
The 0x means it's hexadecimal, followed by 6
digits going from 0 to 15, except they are noted A=10, B=11, C=12, D=13, E=14
and F=15. The 2 first digits code the red (FF is totally red, 00 is no red), the
2 middle digits code the green and the last 2 code the blue.
Now to get a random color, all we have to do is take a random hexadecimal value,
between 0x000000 and 0xFFFFFF, and then round it. Then we can do whatever we
want with it (check the setRGB() tutorial for more information about that
function). Here I tint an object called square:
myColor = Math.round(
Math.random()*0xFFFFFF );
myColoredObject = new Color (_root.square);
myColoredObject.setRGB(myColor);