Second AS3 Snippet of the day…

{0 notes} home

A coworker and I drove ourselves halfway to insanity trying to figure out why the number Powerpoint was spitting out as a color wasn’t translating correctly when we used it in Flash.

I vaguely remembered something about the number being a decimal representation of the RGB values instead of the hex values, so after much Googling and translating from VB to AS3, I give you:

function decToColor(dec:Number):Number {
	var red:int = Math.floor(dec & 0xFF);
	var green:int = Math.floor((dec & 0xFF00) / 256);
	var blue:int = Math.floor(dec / 65536);
	
	return red<<16 | green<<8 | blue;
}
blog comments powered by Disqus