I found this code in a board and I think that it will be useful for making game. Code is about add zero too number.
| Number.prototype.addZeros = function(p) { return new Array(p - length(this) + 1).join('0') + this; }; |
// Usage:
points = 200;
trace(points.addZeros(10));
or as a class:
| Score = function (points) { this.points = points; }; Score.prototype.display = function(p) { |
// Usage:
myScore = new Score(200).display(10);
trace(myScore);
Note-16-04-06 I just check for this script and it can use in old version. If you try to join by zero and trace for result, you will see "undefined" insert between zero number. So you have to remove "undefined" out.