Prototype: AddZeros [Flash 8]
| Beiträge: 130 Wohnort: Berlin/Germany Registriert: Mar 2002
| 02.07.2003, 18:47
Nullen hinzufügen für Punktestände
Prototype:
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Number.prototype.addZeros = function(p) {
return new Array(p - length(this) + 1).join('0') + this;
};
// oder als Klasse:
Score = function (points) {
this.points = points;
};
Score.prototype.display = function(p) {
return new Array(p - length(this.points) + 1).join('0') + this.points;
};
|
Beispiel Aufruf:
ActionScript:1 2 3 4 5 6 7 | // Verwenden
punkte = 200;
trace(punkte.addZeros(10)); // result: 0000000200
// Verwenden
myScore = new Score(200).display(10);
trace(myScore);
|
[Flashstar]
http://www.flashstar.de | | | Beiträge: 6981 Wohnort: München Registriert: Jan 2002
| 26.02.2004, 14:40
Mit Flash MX 2004 funktioniert das ganze so leider nicht mehr.
Hier ein MX 2004 Variante:
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Number.prototype.addZeros = function(p) {
while(length(this) < p) {
this = '0' + this;
}
return this;
};
// oder als Klasse:
Score = function (points) {
this.points = points;
};
Score.prototype.display = function(p) {
while(length(this.points) < p) this.points = '0' + this.points;
return this.points;
};
|
Grüsse,
Sebastian Wichmann
Flashhilfe.de Webmaster
http://www.flashhilfe.deJavaScript & JavaFX Freelancer || Flashhilfe @ Twitter || XING Profil | |
| Ähnliche Beiträge zum Thema | |
|
Flashhilfe.de Flash Platform Tipps & Tutorials Flash Platform Andere Programmiersprachen Jobangebote Diskussionen
Flashhilfe News 
Regeln & Bedingungen
|