How do I convert an integer to a string value? This must be easy. \"Ya guys in SO are da best at explaining.\" I\'m still working on these dumb counters.
I use 5 + ""
, any time you add ""
(no character) , it converts anything to a string and it's easy to remember.
myInt.toString();
I was under the impression AS3 has a String() method which will explicitly coerce a variable of the type number into a String. Integers can be converted to numbers easily enough, and i'm pretty sure it would be done implicitly in this case.
text = String(number);
very simple ==>
var myint:int = 500;
var myintToString:String = myint+"";
COUNTER "DYNAMIC TEXT" with zero values solution
I'm posting on behalf of Ed, a human that helped me over the phone. It was a problem with the string arguments and the syntax in mytext.
//CA, NC, LONDON, ED "increments"
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
mytext.text = formatCount(fcount);
}
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 : fraction);
}