<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Inside Snipplr.com &#187; ActionScript 3</title>
	<atom:link href="http://snipplr.com/blog/category/actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://snipplr.com/blog</link>
	<description>s nipple r &#60;em&#62;dot com!&#60;/em&#62;</description>
	<lastBuildDate>Wed, 23 Nov 2011 17:51:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AS2 / AS3 Game Score Formatter</title>
		<link>http://snipplr.com/blog/2008/09/11/as2-as3-game-score-formatter/</link>
		<comments>http://snipplr.com/blog/2008/09/11/as2-as3-game-score-formatter/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 21:17:28 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[featured]]></category>

		<guid isPermaLink="false">http://snipplr.com/blog/?p=97</guid>
		<description><![CDATA[Often when developing games I have the need to add zeros in front of my score depending on how many digits are to be shown. For instance, even though I may have a score of 5, I still need to display 00005 on the screen.

To do this I wrote this useful little function for just [...]]]></description>
			<content:encoded><![CDATA[<p>Often when developing games I have the need to add zeros in front of my score depending on how many digits are to be shown. For instance, even though I may have a score of 5, I still need to display 00005 on the screen.</p>

<p>To do this I wrote this useful little function for just that purpose.</p>

<p><code>trace(formatScore(555, 6)); // 000555
trace(formatScore(-555, 6)); // -000555</code></p>

<p><code>function formatScore( value:Number, digits):String {</code></p>

<p><code>var scoreStr:String = '';
var tempScore:String = '';</code></p>

<p><code>var scoreLen:Number = value.toString().length;
var indexOfNeg:Number = value.toString().indexOf('-');</code></p>

<p><code>if (value.toString().charAt(0) == '-') {</code></p>

<p><code>tempScore = String(value.toString().substring(indexOfNeg+1, scoreLen));
scoreLen--;
}
for (var i:Number = 0; i&lt;(digits-scoreLen); i++) {</code></p>

<p><code>scoreStr += '0';
}
var posAnswer:String = String(scoreStr+value.toString());
var negAnswer:String = '-'+String(scoreStr+tempScore.toString());
var answer:String = (indexOfNeg == -1) ? posAnswer : negAnswer;</code></p>

<p><code>return answer;
}</code></p>

<p><em>Jeremy Sykes is a Flash Game Programmer &amp; Developer</em></p>
]]></content:encoded>
			<wfw:commentRss>http://snipplr.com/blog/2008/09/11/as2-as3-game-score-formatter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

