konvertieren einer Ganzzahl in einen string as3
Wie wandle ich einen integer in einen string-Wert?
Das muss einfach sein. "Ya Jungs SO sind da am besten an zu erklären." Ich arbeite immer noch auf diese blöde Zähler.
MÜSSEN SICH DIESE ZUSAMMEN
//My counter project "sends to dynamic text field"
var timer:Timer = new Timer(10);
var count:int = 0; //start at -1 if you want the first decimal to be 0
var fcount:int = 0;
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
function incrementCounter(event:TimerEvent) {
count++;
//
fcount=int(count*count/10000);//starts out slow... then speeds up
//
var whole_value:int = int(fcount / 100); //change value
var tenths:int = int(fcount / 10) % 10;
var hundredths:int = int(fcount) % 10;
mytext.text = whole_value + " : " + tenths + hundredths;
}
NULLEN PLATZHALTER
//Code for adding "zero placeholders"
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction;
}
function test():void {
for (var i:int = 1; i<100000; i += 3) {
trace(i + " -> " + formatCount(i));
}
}
Immer access of undefined property, myInt.toString();
//joined together
var timer:Timer = new Timer(10);
var count:int = 0; //start at -1 if you want the first decimal to be 0
var fcount:int = 0;
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
myInt.toString();
function incrementCounter(event:TimerEvent) {
count++;
//
fcount=int(count*count/10000);//starts out slow... then speeds up
//
var whole_value:int = int(fcount / 100); //change value
var tenths:int = int(fcount / 10) % 10;
var hundredths:int = int(fcount) % 10;
mytext.text = whole_value + " : " + tenths + hundredths;
}
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction;
}
function test():void {
for (var i:int = 1; i<100000; i += 3) {
trace(i + " -> " + formatCount(i));
}
}
KEINEN FEHLER JETZT, BRACH ES EINEN ANDEREN WEG,
var timer:Timer = new Timer(10);
var count:int = 0; //start at -1 if you want the first decimal to be 0
var fcount:int = 0;
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
function incrementCounter(event:TimerEvent) {
count++;
//
fcount=int(count*count/10000);//starts out slow... then speeds up
//
var whole_value:int = int(fcount / 100); //change value
var tenths:int = int(fcount / 10) % 10;
var hundredths:int = int(fcount) % 10;
//////////////
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction;
}
function test():void {
for (var i:int = 1; i<100000; i += 3) {
trace(i + " -> " + formatCount(i));
}
}
//////////////
mytext.text = formatCount(whole_value + " : " + tenths + hundredths);
//mytext.text = whole_value + " : " + tenths + hundredths;
}
BEISPIELE
//string to number
var myString:String = "5";
var myNumber:Number = Number(myString);
//number to string
var myNumber:Number= 5;
var myString:String= String(myNumber);
//string to int (integer)
var myString:String = "5";
var myInt:int = int(myString);
- wenn ich verstehen deine Frage richtig, Beispiel #2 zu beantworten scheint es...? was ist das problem, das Sie gegenüberstellen?
- Fügen Sie die Skripts zusammen und spielen. 1120: Access of undefined property myInt.toString(); "was bin ich?
- Wo ist myInt definiert werden, bevor Sie die toString() ?
Du musst angemeldet sein, um einen Kommentar abzugeben.
myInt.toString();
War ich unter dem Eindruck AS3 ist ein String () - Methode, die explizit zwingen, eine variable des Typs Zahl in einen String. Ganzzahlen können in zahlen umgewandelt werden leicht genug, und ich bin mir ziemlich sicher, dass es getan werden würde implizit in diesem Fall.
Benutze ich
5 + ""
jedem hinzufügen""
(kein Zeichen) , es wandelt alles in einen string und es ist leicht zu merken.COUNTER "DYNAMISCHER TEXT" mit null-Werten-Lösung
Ich werde Entsendung im Auftrag von Ed, einem Menschen, der mir half, mich über das Telefon. Es wurde ein problem mit der string-Argumente und die syntax in mytext.
sehr einfach ==>