views:

32

answers:

4

How do I fix this string error? This numberic counter works without the ADDITION STRING ARGUMENT. It's function is to add zero placeholders to the counter. It's close, but I need a second opinion.

COUNTER "all zeros, no count"

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;

//ADDITIONAL STRING ARGUMENTS FOR "ZERO PLACEHOLDER"

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

///////////////////END STRING ARGUMENT///////////////////
 // mytext.text = whole_value + " : " + tenths + hundredths;  
}

alt text

"thanks yal, hope to see the last of this problem, please help"

+2  A: 

You are calling your formatCount function with a String arguments but it is expecting an int value: your call should be:

mytext.text = formatCount(whole_value) + " : " + tenths + hundredths;

But i don`t know what are you expecting the output to be ?

Patrick
That's all I needed. Thanks so much.
VideoDnd
+1  A: 

Patrick is right on this question.

Just couldn't resist adding this one line snippet...

var num:Number = 666;    

for(var str:String = String((num/100).toFixed(2)); (str = "0" + str).length < 10;);

trace(str);
Theo.T
666, the project from hell. I could go on, but I'll calm down. Thanks for the well needed jab.
VideoDnd
A: 
//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
A: 
//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