Merrill, Jason wrote:
How can I translate the ColorPicker.selectedValue to a 6 digit hex
number?  i.e. if the color selected is, 000066, if I trace
ColorPicker.selectedColor, traces 102.  I tried gooling for an
Actionscript hex converter, but didn't come up with anything.  Thanks.



This may not help, but you can get each RGB color value from the selectedValue:

//--------------------------
  redValue = selectedValue >> 16;
  greenValue = (selectedValue >> 8) & 255;
  blueValue = selectedValue & 255;
//--------------------------

If you're manipulating the number, as opposed to storing or displaying it, can't you just work with it in decimal, even if you're using hex numbers as operands? This should change the green value to 256:

//--------------------------
  newColorValue = selectedValue | 0x00FF00;
//--------------------------


If you do need to convert it, what about something like this? (Tested only in AS2, but you get the idea.):

//--------------------------
function decimalToHex(decVal:Number):String {
  var digits:String = "012345689ABCDEF";
  var returnStr:String = "";
  while (decVal) {
    returnStr += digits.substr(decVal & 15 -1, 1);
    decVal >>= 4;
  }
  return returnStr;
}

trace(decimalToHex(65535));

// outputs "FFFF"

//--------------------------

-jim

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to