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:
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,

Flash Tutorial #2 – The Basics of Actionscript 3.0

Hey there. I just finished up another tutorial about the basics of Actionscript 3.0 (AS3). The video is about 36 minutes long and covers a wide range of topics, including: variables, conditionals, operators, functions, events, and other general basic ideas in Actionscript 3.0 (and many other languages). By the way, I talk about all those pretty much in that order, slipping in little bits of data about other things as I progress through the video.

I also finally got around to submitting SpaceFlyer online, so the project page is now updated with a playable link to the game, or you can click here. I’ll be straight about this game, it isn’t really pretty, and it doesn’t exactly have a great story line, BUT there are some sweet mechanics!

Hope you enjoy them both