字符串错误“调试中没有”动作脚本3

时间:2010-02-10 22:55:59

标签: flash actionscript-3 string

如何解决此字符串错误?这个数字计数器在没有附加字符串论据的情况下工作。它的功能是向计数器添加零占位符。它很接近,但我需要第二个意见。

反“全零,不计数”

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 http://www.ashcraftband.com/myspace/videodnd/icon-3.jpg

“谢谢你,希望看到最后一个问题,请帮忙”

3 个答案:

答案 0 :(得分:1)

您正在使用formatCount参数调用String函数,但它需要一个int值:您的调用应该是:

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

但我不知道你对输出的期望是什么?

答案 1 :(得分:0)

帕特里克对这个问题是正确的。

无法抗拒添加这一行代码段......

var num:Number = 666;    

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

trace(str);

答案 2 :(得分:0)

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