Saturday, June 26, 2010

AS3 Adding zeros to score

A lot of games have this feature, and the question has been asked on some flash game development forums recently: "How do you make your score appear with zeros in the beginning? Like 000350 and 003500."


Here's the code:



var score=350;
var maxchars=6;
var str:String = score.toString();
var more = maxchars - str.length;
var i:int;
var n:String = "";
for (i=0; i < more; i++){n+="0"};
trace(n+str);

No comments:

Post a Comment