Convert Unsigned Integers to Hexadecimal Strings

So, you wanna convert a uint to hex in AS3, huh? Well, this is how you do it:

function uintToHex(val:uint):String {
	var pref:String = "000000";
	var str:String = String(pref + val.toString(16));
	return "#" + str.substr(-6).toUpperCase();
}

What I think this is really useful for is converting randomly generated colors to hexadecimals so that you can access them later. I mean, it’s not that the uint equivalents are bad or anything, but the hex codes are generally easier to work with.

Also, awhile back I was browsing the web seeing how other people managed to do this, and I found this post: Tylerbeck.com
Feel free to check it out. It’s really great for understanding hexadecimals a bit more. It’s a longer function, but does the exact same thing as this one.

Good Luck,
Thomas