工作柜台的“零占位符”as3

时间:2010-02-10 03:02:43

标签: flash actionscript-3

如何为计数器设置零占位符?

我的想法是“if”条件更大 较小的会工作。

if count is more than .00 and less than 10.00, add "0000000" etc.

alt text http://www.ashcraftband.com/myspace/videodnd/icon_3.jpg

CODE “来自一些最优秀的人士”

//counts
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++;  

  var whole_value:int = int(count / 100); //change value 
  var tenths:int = int(count / 10) % 10;   
  var hundredths:int = int(count) % 10;   

  mytext.text = whole_value + " : " + tenths + hundredths;  
} 

///////////////////////////////////////////////

//counts and accelerates
//CA, NC, LONDON "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 
  //
  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;  
}   

alt text http://www.ashcraftband.com/myspace/videodnd/icon-3.jpg

我做零... eeeeerrrrrrr ...不是动画,不要笑! 诅咒

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

“感谢帮助人员”

4 个答案:

答案 0 :(得分:1)

这是一个按照你想要的方式格式化它的功能。

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

示例输出(添加间距):

1     -> 0000000.01
4     -> 0000000.04
7     -> 0000000.07
10    -> 0000000.10
13    -> 0000000.13
97    -> 0000000.97
100   -> 0000001.00
103   -> 0000001.03
235   -> 0000002.35
520   -> 0000005.20
997   -> 0000009.97
1000  -> 0000010.00
1003  -> 0000010.03
99997 -> 0000999.97

答案 1 :(得分:0)

据我所知,你需要自己做:

这里有一些code

答案 2 :(得分:0)

这是一个简单的例子,非常简单,但如果您有任何问题,请告诉我。

var n:Number = 999.99123;
var minLength:int = 15;
var s:String = n.toFixed(2);
var diff:int = minLength - s.length;

while (diff > 0) {
    s = '0' + s;
    diff--;
}

trace(s);

编辑:您希望“十分之一”始终为0吗?

答案 3 :(得分:0)

与零利益相关者进行数百万的比较

//CA, NC, LONDON, ED, GA "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); 
}