convert an integer to a string as3

前端 未结 5 788
死守一世寂寞
死守一世寂寞 2020-12-20 16:58

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.

相关标签:
5条回答
  • 2020-12-20 17:28

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

    0 讨论(0)
  • 2020-12-20 17:31

    myInt.toString();

    0 讨论(0)
  • 2020-12-20 17:43

    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);
    
    0 讨论(0)
  • 2020-12-20 17:46

    very simple ==>

    var myint:int = 500;
    var myintToString:String = myint+"";
    
    0 讨论(0)
  • 2020-12-20 17:51

    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); 
    } 
    
    0 讨论(0)
提交回复
热议问题