This is my 2-part question. My understanding is small so "beer" with me.
This example counts from 1-100. I want the decimal keep counting to ten over-and over. (a.)How do I loop the decimal? 1-10 over-and-over. (b.)How to I get the whole and decimal value on the same dynamic text field?
alt text http://www.ashcraftband.com/myspace/videodnd/icon9.jpg
THING
"It's a counter with whole and decimal values" -text filed receive string of whole number and decimal place -decimal fast, whole number slowCODE
/*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.) //RESET START function countdown($evt:TimerEvent):void { timer.reset(); timer.start();VERBOSE EXAMPLE
if Number's less than 11, do it again(b.)
//STRING var time:String =whole + ":" + decimal;time_txt.text = countdown;
UNEXPECTED PROBLEMS
-changing values (1000, 100) didn't work "affects the other number" -I don't know how I'm going to add velocity to something in the timer class "an other post"alt text http://www.ashcraftband.com/myspace/videodnd/icon_1.jpg
THE DECIMALS STAY IN THEIR PLACE
//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 val开发者_如何学Pythonue
var tenths:int = int(count / 10) % 10;
var hundredths:int = int(count) % 10;
mytext.text = whole_value + " : " + tenths + hundredths;
}
CRITERIA "I forgot to include 2/10/10"
WHOLES X 10 multiplesDECIMALS
tenths dec = 10% of ones hundreds dec = 10% of tenths dec"thanks for the help everyone"
It's probably better to use your own count variable instead of the one from the timer. You want something like the following. Every time the timer ticks the count will update by one. The "%" is the 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;
}
To adapt Nathan's answer for 100/ths you could do something like this:
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;
}
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();
}
}
精彩评论