views:

916

answers:

4

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.

NEED TO JOIN THIS TOGETHER

//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;  
} 

ZEROS PLACEHOLDER

//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)); 
    } 
} 

Getting 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));  
        }  
    } 

NO ERROR NOW, BROKE IT SOME OTHER WAY

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;  
}

EXAMPLES

// 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);

+2  A: 

Hi, use this:

myInt.toString();
Tyler Egeto
Thanks man. Keep an eye on this thead if I have trouble.
VideoDnd
Thought that did it. My error 1120: Access of undefined property myInt.toString(); "See edit I made?"
VideoDnd
I want you to read the error and figure out whats wrong with that. (I'm not trying to be an ass, you just need to know how to debug) Let me know if you can't figure it out, and I'll tell you.
Tyler Egeto
myInt does not exist? No wonder you are getting the error
0A0D
+1  A: 

I use 5 + "", any time you add "" (no character) , it converts anything to a string and easy to remember.

Daniel
A: 

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); 
} 
VideoDnd
+1  A: 

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);
revenantphoenix