January 19, 2010 at 12:48 pm | blabbing, Flash, Programming, web.

Found a great utility to help with little chores like this in Flash.

http://casalib.org/ has made a nice Flash framework that you can use for AS 2.0 or 3.0 to do lots of stuff. Great DOCs section of the site as well that shows how each function works.

I used the NumberUtil.format function to add leading zeros to a variable that I was outputting to a text box and it was as easy as pie. Unpack the ZIP file that you can download from the site and put the “org” folder that is inside the code folder in the same directory as your Flash file (fla).

import that class at the head of your actionscript

import org.casalib.util.NumberUtil;

Next use this trace command as a guide on how the NumberUtil.format command works.

trace(NumberUtil.format(1234567, 8, ",")); // Traces 01,234,567

Mine worked something like this. I didn’t need the commas to separate the numbers I just needed the leading zeros. This turned my original number that was something like this 5045345 to this 005045345.

tf.text = NumberUtil.format(tf.text, 9);