Dear all,
This may, or may not, be useful to some of you... ...but I've recently had to put a websafe palette into Flash, and I found that the following code is the best way to create the relevant hex codes (which can then be assigned to movies using setRGB, etc). Essentialy it creates an array called 'pal' with the websafe 216 colour codes in it. (I've got an example palette that you can select colours from if anyones interested).
Anyway - may not be useful, but hopefully might save someone a headache!
Bye for now,
PetitPal.
-------------------- script starts -------------------
// this function creates the web safe palette in an array
// PetitPal 2001
function create_palette() {
// first, need to create array (zero based so one less than need!)
pal = new Array(215);
pal_count = 0;
// outer loop is blue section, then green, then red...
for (blue_count=0; blue_count<=5; blue_count++) {
blue_hex = make_hex(blue_count);
for (green_count=0; green_count<=5; green_count++) {
green_hex = make_hex(green_count);
for (red_count=0; red_count<=5; red_count++) {
red_hex = make_hex(red_count);
// now add hex code to array and increment count...
pal[pal_count] = red_hex + green_hex + blue_hex;
pal_count++;
}
}
}
}
// this transforms count (from create_palette) into
// relevant hex value...
function make_hex(make_hex_count) {
if (make_hex_count == 0) { return "00"; }
if (make_hex_count == 1) { return "33"; }
if (make_hex_count == 2) { return "66"; }
if (make_hex_count == 3) { return "99"; }
if (make_hex_count == 4) { return "CC"; }
if (make_hex_count == 5) { return "FF"; }
}
-------------------- script ends -------------------
This may, or may not, be useful to some of you... ...but I've recently had to put a websafe palette into Flash, and I found that the following code is the best way to create the relevant hex codes (which can then be assigned to movies using setRGB, etc). Essentialy it creates an array called 'pal' with the websafe 216 colour codes in it. (I've got an example palette that you can select colours from if anyones interested).
Anyway - may not be useful, but hopefully might save someone a headache!
Bye for now,
PetitPal.
-------------------- script starts -------------------
// this function creates the web safe palette in an array
// PetitPal 2001
function create_palette() {
// first, need to create array (zero based so one less than need!)
pal = new Array(215);
pal_count = 0;
// outer loop is blue section, then green, then red...
for (blue_count=0; blue_count<=5; blue_count++) {
blue_hex = make_hex(blue_count);
for (green_count=0; green_count<=5; green_count++) {
green_hex = make_hex(green_count);
for (red_count=0; red_count<=5; red_count++) {
red_hex = make_hex(red_count);
// now add hex code to array and increment count...
pal[pal_count] = red_hex + green_hex + blue_hex;
pal_count++;
}
}
}
}
// this transforms count (from create_palette) into
// relevant hex value...
function make_hex(make_hex_count) {
if (make_hex_count == 0) { return "00"; }
if (make_hex_count == 1) { return "33"; }
if (make_hex_count == 2) { return "66"; }
if (make_hex_count == 3) { return "99"; }
if (make_hex_count == 4) { return "CC"; }
if (make_hex_count == 5) { return "FF"; }
}
-------------------- script ends -------------------