Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a websafe palette hex codes in flash - Script Listing =)

Status
Not open for further replies.

PetitPal

Programmer
May 2, 2001
243
0
0
GB
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 &quot;00&quot;; }
if (make_hex_count == 1) { return &quot;33&quot;; }
if (make_hex_count == 2) { return &quot;66&quot;; }
if (make_hex_count == 3) { return &quot;99&quot;; }
if (make_hex_count == 4) { return &quot;CC&quot;; }
if (make_hex_count == 5) { return &quot;FF&quot;; }
}

-------------------- script ends -------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top