用小数位“动态文本”AS3计数

时间:2010-02-09 18:56:24

标签: flash actionscript-3

这是我的两部分问题。我的理解很小,所以“喝啤酒”。

此示例从1-100开始计算。我希望小数一遍又一遍地计数到十。 (a。)如何循环小数? 1-10次反复。 (b。)如何在同一动态上获得整数和小数值 文字字段?

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

THING
“它是一个具有整数和十进制值的计数器” -text归档接收整数和小数位的字符串
-decimal fast,整数慢

CODE

/*I made two text fields, change the names and values, but the values didn't
respond properly. 1000 = 1 sec and 100 = 1/10th or a second. The whole thing changed.*/
//working code

var timer:Timer = new Timer(1000, 100);
timer.addEventListener(TimerEvent.TIMER, countdown);
timer.start();
function countdown(event:TimerEvent) {
    myText.text = String(0 + timer.currentCount);
}

IDEAS
(a。)中
//重置开始
函数倒计时($ evt:TimerEvent):void {
    timer.reset();
    timer.start();

VERBOSE示例
如果Number小于11,请再次执行

(B)
// STRING
var time:String = whole +“:”+ decimal;

time_txt.text =倒计时;

意外问题
- 改变值(1000,100)不起作用“影响其他数字”
- 我不知道我将如何在计时器类“另一篇文章”中添加速度“

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

DECIMALS留在他们的地方

//CA, NC, LONDON
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; 
}

标准“我忘了包括2/10/10” 的整体而
X 10倍数

DECIMALS
十分之一=十分之一 数百dec =十分之十十分之十

“感谢大家的帮助”

3 个答案:

答案 0 :(得分:3)

最好使用自己的count变量而不是计时器中的变量。你想要的东西如下。每次计时器滴答时,计数将更新一次。 “%”是modulo operator

var timer:Timer = new Timer(1000);
var count:int = 0; //start at -1 if you want the first decimal to be 0

timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();


function incrementCounter(event:TimerEvent) {
  count++;

  var whole_value:int = int(count / 10);
  var decimal_value:int = count % 10; 
  mytext.text = whole_value + " : " + decimal_value;
}

答案 1 :(得分:1)

要使Nathan's answer适应100 / th,你可以这样做:

function incrementCounter(event:TimerEvent) {
  count++;

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

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

答案 2 :(得分:0)

var timer:Timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, countdown);
timer.start();
var time = 2000;
function countdown(event:TimerEvent) {
 time -= 1;
 var seconds = int(time/10);
 var tenths = int(time - seconds*10);
 time_txt.text = seconds + " : " + tenths;
    if (time == 0) {
        timer.stop();
    }
}