Internet Explorer 6 is not supported.
Upgrade to view this site.

Blog Archive

Results for the blog tag snippets.

Hex to Unsigned Integer and Back Again

Here are some quick one line wonders. From reading some stuff here and there I was able to fashion 2 functions for handling the conversion between hex strings and unsigned integers. Most of the time a uint is asked for when it comes to color, but some things like the StyleSheet object asks for a string value of a hex color like you would use in CSS.

I guess these function names got a little long, but they are very descriptive to what they do, and when you use Flex with it’s completion function name brevity isn’t as much of an issue as it is with Flash.

1
2
3
4
5
6
7
8
9
10
11
12
function hexColorToUnsignedInteger(hex:String):uint
{
	return uint("0x" + hex.split("#")[1]);
}
 
function unsignedIntegerToHexColor(num:uint):String
{
	return String("#" + (num.toString(16).toUpperCase()));
}
 
trace(hexColorToUnsignedInteger("#FF0000"));
trace(unsignedIntegerToHexColor(0xFF0000));

Get a Query String From a SWF File

If you want to get a query string off a SWF file name there is a short line of code that does it. This is one of those things that I just can’t figure out logically; I just have to memorize how to do it. I’ve done this once or twice before in AS2 and it was a little bit easier then. This points to the LoaderInfo of the main SWF file. Then you get the parameters property from there. The FlashVars parameter in the SWF’s HTML page does the same thing as adding a query string to the file name.

1
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

For the SWF file name “player.swf?src=video.flv” the code to get the src value would be the following.

1
2
var src:String = paramObj["src"]; //would get "video.flv"
var srcAlso:String = paramObj.src; //same using property instead